Deploy with Helm

Use Helm in a Codefresh pipeline

Helm is the package manager for Kubernetes.
Codefresh has comprehensive support for Helm:

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

At least one Kubernetes cluster in your Codefresh account.

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.

Pipeline for Helm deployment

Pipeline for Helm deployment

Here is the whole pipeline:

codefresh-do-not-store.yml

version: '1.0'
stages:
  - prepare
  - build
  - deploy
steps:
  clone:
    title: Cloning main repository...
    stage: prepare
    type: git-clone
    arguments:
      repo: codefresh-contrib/helm-sample-app
      revision: master
      git: github
  build:
    title: Building Docker Image
    stage: build
    type: build
    working_directory: ./helm-sample-app
    arguments:
      image_name: helm-sample-app-go
      tag: multi-stage
      dockerfile: Dockerfile
  deploy:
    title: Deploying Helm Chart
    type: helm:1.1.12
    stage: deploy
    working_directory: ./helm-sample-app
    arguments:
      action: install
      chart_name: charts/helm-example
      release_name: my-go-chart-prod
      helm_version: 3.0.2
      kube_context: my-demo-k8s-cluster
      custom_values:
        - 'buildID=${{CF_BUILD_ID}}'
        - 'image_pullPolicy=Always'
        - 'image_tag=multi-stage'
        - 'replicaCount=3'
        - 'image_pullSecret=codefresh-generated-r.cfcr.io-cfcr-default'

This pipeline does the following:

  1. Clones the source code through a Git clone step
  2. Builds a docker image through a build step
  3. Deploys the Helm chart to a cluster named my-demo-k8s-cluster using the Helm step from the Step Marketplace.

In this example, charts/helm-example refers to the filesystem location in the code that was just checked out.

The deployment will be visible in the Helm releases dashboard.

Helm release view

Helm release view

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.

Using the default Helm repository in a Pipeline

Using the default Helm repository in a Pipeline

Once that is done you can change your pipeline to also store the chart first and then deploy it.

Pipeline for Helm deployment that stores chart

Pipeline for Helm deployment that stores chart

Here is the whole pipeline:

codefresh.yml

version: '1.0'
stages:
  - prepare
  - build
  - store
  - deploy
steps:
  clone:
    title: Cloning main repository...
    stage: prepare
    type: git-clone
    arguments:
      repo: codefresh-contrib/helm-sample-app
      revision: master
      git: github
  build:
    title: Building Docker Image
    stage: build
    type: build
    working_directory: ./helm-sample-app
    arguments:
      image_name: helm-sample-app-go
      tag: multi-stage
      dockerfile: Dockerfile
  store:
    title: Storing Helm Chart
    type: helm:1.1.12
    stage: store
    working_directory: ./helm-sample-app
    arguments:
      action: push
      chart_name: charts/helm-example
      kube_context: my-demo-k8s-cluster
  deploy:
    type: helm:1.1.12
    stage: deploy
    working_directory: ./helm-sample-app
    arguments:
      action: install
      chart_name: charts/helm-example
      release_name: my-go-chart-prod
      helm_version: 3.0.2
      kube_context: my-demo-k8s-cluster
      custom_values:
        - 'buildID=${{CF_BUILD_ID}}'
        - 'image_pullPolicy=Always'
        - 'image_tag=multi-stage'
        - 'replicaCount=3'
        - '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:

Stored Helm chart

Stored Helm chart

It is also possible to run your own Helm commands in a Codefresh pipeline.

CD pipeline examples
Codefresh YAML for pipeline definitions
Steps in pipelines
Creating pipelines
How Codefresh pipelines work