Deploy with Helm
Use Helm in a Codefresh pipeline
Helm is the package manager for Kubernetes. Codefresh has comprehensive support for Helm:
- You get a free built-in Helm repository with each Codefresh account.
- You can track your charts in the Helm chart dashboard.
- You can view your deployments in your Helm Release dashboard.
- You can promote Helm releases in your Helm environment dashboard.
- You can add any external Helm repository on any other cloud provider.
Codefresh also provides a pipeline step for deploying with Helm.
For more insights on Helm charts see also our Helm best practices guide.
The example Helm project
You can see the example project at https://github.com/codefresh-contrib/helm-sample-app. The repository contains a simple Go application a Dockerfile and an example chart.
Prerequisites
You need to have added at least one Kubernetes cluster in your Codefresh account.
You should also have installed the server side of Helm 2 (Tiller) using helm init
. This command is best run from the cloud console of your cluster.
CI/CD pipeline with Helm deployment
It is possible to deploy directly a Helm chart as it exists on the filesystem. This is not the recommended way to use Helm, because you are bypassing the Helm chart repository, but it is certainly the simplest Helm pipeline possible.
Here is the whole pipeline:
codefresh.yml
version: '1.0'
stages:
- prepare
- build
- deploy
steps:
main_clone:
title: Cloning main repository...
stage: prepare
type: git-clone
repo: 'codefresh-contrib/helm-sample-app'
revision: master
git: github
MyAppDockerImage:
title: Building Docker Image
stage: build
type: build
image_name: helm-sample-app-go
working_directory: ./
tag: 'multi-stage'
dockerfile: Dockerfile
DeployMyChart:
image: 'codefresh/cfstep-helm:2.12.3'
title: Deploying Helm chart
stage: deploy
environment:
- CHART_REF=charts/helm-example
- RELEASE_NAME=my-go-chart-prod
- KUBE_CONTEXT=my-demo-k8s-cluster
- VALUE_image_pullPolicy=Always
- VALUE_image_tag='multi-stage'
- VALUE_replicaCount=3
- VALUE_image_pullSecret=codefresh-generated-r.cfcr.io-cfcr-default
This pipeline does the following:
- Clones the source code with a Git clone step
- Builds a docker image using a Build step
- Deploys the Helm chart to a cluster named
my-demo-k8s-cluster
Note that in this example charts/helm-example
refers to the filesystem location in the code that was just checked out.
If you want to run this example yourself, make sure to edit the chart and put your own values there for the Docker image.
CI/CD pipeline with Helm deployment that also stores the chart
It is recommended to use a Helm repository to store your chart before deploying it. This way you know what is deployed in your clusters and you can also reuse charts in other installations.
First of all you need to import in your pipeline from the shared configuration the settings for the internal Helm repository (or any other external repository that you have setup in Codefresh). This will make available the internal Helm repository to your pipeline so that it can push/pull Helm charts from it.
Once that is done you can change your pipeline to also store the chart first and then deploying it.
Here is the whole pipeline:
codefresh.yml
version: '1.0'
stages:
- prepare
- build
- deploy
steps:
main_clone:
title: Cloning main repository...
stage: prepare
type: git-clone
repo: 'codefresh-contrib/helm-sample-app'
revision: master
git: github
MyAppDockerImage:
title: Building Docker Image
stage: build
type: build
image_name: helm-sample-app-go
working_directory: ./
tag: 'multi-stage'
dockerfile: Dockerfile
StoreChart:
title: Storing Helm chart
stage: deploy
image: 'codefresh/cfstep-helm:2.12.3'
environment:
- ACTION=push
- CHART_REF=charts/helm-example
DeployMyChart:
image: 'codefresh/cfstep-helm:2.12.3'
title: Deploying Helm chart
stage: deploy
environment:
- CHART_REF=charts/helm-example
- RELEASE_NAME=my-go-chart-prod
- KUBE_CONTEXT=my-demo-k8s-cluster
- VALUE_image_pullPolicy=Always
- VALUE_image_tag='multi-stage'
- VALUE_replicaCount=3
- VALUE_image_pullSecret=codefresh-generated-r.cfcr.io-cfcr-default
After you finish running your pipeline, not only the deployment will take place, but you will also see your chart in your Helm Chart dashboard:
It is also possible to run your own Helm commands in a Codefresh pipeline.