Improving Kubernetes deployments with Helm


post-image

I recently blogged about automated deployments to Kubernetes using GitLab. One of the steps required when automating deployments is replacing the Docker tag with the correct value in the Kubernetes Deployment. In that blog post, this looks like the following:

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata: []
spec:
  template:
    spec:
      containers:
        image: sanderknape/go-hello-world:<VERSION>

The string is then replaced in the GitLab pipeline as follows:

sed -i "s/<VERSION>/${CI_COMMIT_SHORT_SHA}/g" deployment.yaml

This grabs the short SHA hash of the current Git commit that is checked out. Earlier in the pipeline, a Docker image has been built and tagged with that SHA, and pushed to a Docker registry.

The alternative of simply using latest would cause several issues. For example, performing a rollback from latest to latest would not work. In addition, using the SHA means that you always know exactly which version of the code is build into the container.

However, as I also mentioned in that blog post, I’m not too happy with having to use sed to replace the version into the deployment file. To me this is a sign that I’m either doing something that I’m not supposed to do, or that a feature is missing. As I’m following a best practice of not using the latest tag, I’m pretty sure that this is an example of the latter situation.

Continue reading on Sander’s personal blog

Back to blog

We make your organisation cloud ready.

We combine innovation with craftsmanship. We are frontrunners in public cloud. Want to learn more?

Tell us your story