Bake and Deploy Helm Charts on Kubernetes with Spinnaker

Shubham Choudhary
4 min readNov 22, 2020

--

Continuous Delivery pipeline

Helm has become the de-facto package manager for application in Kubernetes. I personally like calling it configuration management for containers.

Spinnaker is an open-source, multi-cloud continuous delivery platform to deploy/upgrade/scale/rollback applications in VMs(AWS EC2, GCE), container orchestrations(K8s, Openstack), etc.

In this article, we’ll see how can we use Spinnaker to deploy any Helm chart i.e deploy a container on Kubernetes.

What is a Helm Chart?

A Helm Chart is a collection of files that describe a related set of Kubernetes resources. Helm can be used to install any containerized application very easily like Nginx, Prometheus, Grafana.

Below is the command to deploy any chart.

helm install release-name my-chart -f values.yaml

Helm does majorly two operations for the above-mentioned command

  • Bake/Generate the chart with the supplied values to generate the K8s manifest. We can see the generated manifest with the below command.

helm template release-name chart-name -f values.yaml

  • It then applies(kubectl apply) the above-generated manifest to K8s. It also adds a lot of labels and annotations on K8s resources for version controlling and its working.

values.yaml is a YAML file that contains the configuration of resources like container image name, tag, number of replicas, resource limits, service ports, ingress, etc.

Helm Best Practice 👉 Build one generic helm chart per application. Maintain values of different envs in GIT where each branch represents an environment like DEV, QA, STG, etc.

Prerequisites for deploying the Helm Chart in Spinnaker

  1. Spinnaker terminologies in terms of K8s.
  2. Container image pushed to any container registry like AWS ECR.
  3. Helm chart pushed to a binary repository like Nexus, Chart Museum, or Artifactory.
  4. values.yaml stored in GIT.
  5. Read and Write access to the namespace of the Kubernetes where you want to deploy the container.

Steps to create a Pipeline in Spinnaker

  • Login in to your Spinnaker. Create an application that represents an actual container application. Then create a pipeline for each environment deployment like deploy-to-dev.
Create Application in Spinnaker
Configure a new pipeline
deploy-to-dev pipeline

Helm two operations can be added as two stages in our pipeline where the output of the first i.e bake stage will be the input of the next i.e deploy stage.

Add Bake Stage

  • Select type as Bake(Manifest)
Add a Stage
Type: Bake(Manifest)
  • Template Renderer: HELM3
  • Name: <RELEASE-NAME>(REQUIRED)
  • Namespace: <NAMESPACE>
  • Point to Helm chart and version.
Enter helm releasename, namespace, and helm chart details

Till here, we have achieved helm template myrelasename -n mynamespace nginx --version 0.1.0

This will take the default values.yaml present in the nginx-0.1.0.tar.gz. But we want to provide different values.yaml based on the environment like here DEV values.

Override values

Spinnaker can read the object from the Bitbucket/GIT/S3. As I am using Bitbucket. I need to provide the location of my values.yaml in the below-mentioned format.

Object Path: https://api.bitbucket.org/2.0/repositories/MYORG/MYCONFIG/src/dev/nginx/values.yaml

File Path: nginx/values.yaml

Add the location of dev nginx values.yaml

Let us now name the output of the above operation as something meaningful like DEV Manifest.

Edit the name of artifacts produced
Edit the name as DEV Manifest

Add Deploy Stage

  • Select type as Deploy(Manifest)
Type: Deploy(Manifest)
  • Select the Account where you want to deploy(If you are not able to see the account then you don’t have access)
  • Override Namespace: Tick(Enabled)
  • Namespace: <NAMESPACE>
Select the K8 account and namespace
  • Now, chose the Artifact(Spinnaker Lingo) ie. Dev Manifest i.e YAML files produced in the previous stage here and save the pipeline.
Use Dev Manifest as Artifact

Similarly, we can add pipeline like deploy-to-qa, deploy-to-stg, deploy-to-prod.

Run the Pipeline 🚀

We can also check the generated YAML

Visualize the resources under the Infrastructure tab.

One nginx pod running

Checkout complete code on GITHUB⚡️ 👉 shubhamc183/helm-spinnaker-demo

--

--