K8s deployments using Spinnaker

Abhinay Byrisetty
5 min readFeb 21, 2022

--

K8s deployments using Spinnaker

Spinnaker is an extremely powerful tool when it comes to managed delivery of cloud-native applications. Kubernetes is one of the widely used deployment platforms in the modern day.

To deploy cloud-native applications to kubernetes clusters using Spinnaker, user has various options as listed below.

  • Deploy using plain text manifest
  • Deploy using artifacts from repo
  • Deploy using helm chart from helm repo
  • Deploy using helm package from git repo
  • Deploy using helm chart from git repo

I’ll dive into each of those options and provide you with the necessary details to implement the same in Spinnaker.

1. Deploy using plain text manifest

Deploying an application to K8s using plain manifest is one of the easiest ways as Spinnaker has a built-in stage called Deploy(Manifest) stage to handle this use case.

In this way, deploy stage of the pipeline would simply have the deployment manifest in the text format as shown below

Deployment manifest as text in the deploy stage of pipeline
K8s deployment pipeline using text manifest

Under Basic Settings, we need to configure Account(target cluster where we want to deploy the manifest) and namespace.

Accounts should be pre-configured via halyard.

2. Deploy using artifact from repo

The idea behind this use-case is typically to have manifest files version controlled by storing them under a git repository or s3 bucket or any other storage location and deploying it using the artifact.

Setup git repo as source of truth for manifests:

Here, I’ll store the deployment manifest under a git repository and configure the git repository as an artifact in halyard configuration using the below commands on halyard pod.

TOKEN_FILE=~/demo-git-token
echo <GITHUB_TOKEN_REDACTED> > $TOKEN_FILE
ARTIFACT_ACCOUNT_NAME=demo-git-account
hal config artifact github enable
hal config artifact github account add $ARTIFACT_ACCOUNT_NAME \
--token-file $TOKEN_FILE
hal deploy apply

Refer to official docs for more details

Deploy using an artifact from github repo

Now, we are good to configure Deploy(Manifest) stage in Spinnaker to deploy using an artifact from git repo.

Deployment configuration

In the image show above, Content URL is the location where deploy manifest is present in a git repo. As I stored it under github, url would be — https://api.github.com/repos/abhinaybyrisetty/k8s-manifests/contents/nginx-deploy.yaml

Pipeline config view

3. Deploy using helm chart from helm repo

Helm is widely used to package, install and manage kubernetes based applications. Spinnaker can deploy K8s applications using helm chart, but it renders the manifests and deploy using them, instead of using helm client under the hood.

In the case, let’s look at how we can deploy a helm chart from a helm repository.

Add helm repository via halyard

hal config artifact helm account add demo-helm-repo --repository <helm_repo_url>hal config artifact helm enablehal deploy apply
Pipeline showing helm bake stage

Bake the helm chart

Unlike, traditional helm deployments, Spinnaker doesn’t directly deploy the helm chart to the target K8s cluster. Spinnaker expects us to first bake the chart, create an artifact and then deploy the rendered manifests using the created artifact.

While baking the helm chart, we need to configure which render engine we want to use as helm2 is still supported by Spinnaker.

We can also override values by overriding keys as shown in the image above or, store the override-values.yaml in a git repo or s3 or any artifactory and use it.

Bake stage produces an artifact that will be used in the subsequent deploy stage. We can also customize the name of the helm chart by editing the below section.

Deploy using the artifact created in bake stage

In the Deploy(Manifest) stage, we need to correctly choose the Manifest Artifact so that the rendered manifest will be deployed.

Refer to the below link for more details on why Spinnaker turns templates into manifests and deploy

4. Deploy using helm package from git repo

In this case, I’ll demonstrate how to store our helm chart as a tar ball in git repo and deploy it using Spinnaker.

Ensure, github artifact is configured in halyard as shown in Case. 2 above.

Bake stage looks similar to Case. 3, but instead of configuring a helm repo as an expected artifact account, we would configure a git repo where our chart is stored as a tar ball as shown below.

In the above image content URL should be as - https://api.github.com/repos/abhinay/k8s-manifests/contents/hello-world/hello-kubernetes-1.0.3.tgz

5. Deploy using helm chart in a git repo

Now, let’s look at another way of deploying K8s applications using Spinnaker.

This method is similar to Case.4, but instead of storing the helm chart as a tar ball in the git repo, we would have the source code of the helm chart directly present in the git repo.

To achieve, this we need to configure a different artifact in Spinnaker of type gitrepo. This shall be done even if a github artifact is already configured and our chart is configured in github.

Instructions to configure gitrepo artifact.

bash-4.4$ TOKEN_FILE=~/gitrepo-creds-file
bash-4.4$ ARTIFACT_ACCOUNT_NAME=demo-gitrepo-artifact
bash-4.4$ hal config artifact gitrepo account add $ARTIFACT_ACCOUNT_NAME --token-file $TOKEN_FILE
bash-4.4$ hal config artifact gitrepo enable
bash-4.4$ hal deploy apply

I hope you learnt something new while going through this blog.

PS: Ofcourse, there is one more way of deploying K8s apps using Spinnaker, using Kustomize as the render Engine. I’ll share details in a separate blog.

--

--