Creating the Helm Chart
To begin, we have created a very simple Helm chart, which we have stored in a GitRepo source repository:
We use a companion
values.yml file to specify the details, including information that identifies which Docker image to deploy.
tag fields that identify the Docker image name and tag are set to environment variables. These reference the
imageTag properties of the Image resource for the Docker image.
When our pipeline runs, the HelmDeploy step will automatically replace these environment variable reference with their values from the Image resource, so that the correct Docker image is deployed through Helm.
For more information on creating Helm charts, see the Helm Chart Template Guide.
The Helm deploy will pull an image from a Docker registry to orchestrate to a Kubernetes cluster.
If your image to deploy is already available in the Docker registry, then you can skip this procedure. However, you will still need an Image resource that specifies the image in the registry.
resources definitions will specify:
simplehelmRepo_docker- The GitRepo source repository where the Dockerfile is stored
simplehelmDockerImage- An Image resource for the Docker image that will be built and pushed to the Docker registry in Artifactory
Using these resources, the pipeline will build the Docker image and push it to a registry in Artifactory.
Publishing the Helm Chart
The example pipeline uses the HelmPublish native step to publish the Helm chart and its companion files to a Helm repository in Artifactory.
resources definitions will specify:
simplehelmRepo_chart- The GitRepo source repository where the Helm chart shown above is stored.
simpleHelmChart- A HelmChart resource that represents the Helm chart published in Artifactory. It specifies the Artifactory repository, chart name, and version for publishing.
Using these resources, the HelmPublish native step will publish the Helm chart from the source repository to an Artifactory repository. (Note that this step as configured does not publish the build info.)
The native step uses the
helm package command to perform publication, so all chart files (
values.yml) will be published as a unit.
Deploying With Helm
The example pipeline uses the HelmDeploy native step to deploy the image to Kubernetes.
The HelmDeploy native step will:
- Use the
simplehelmChartresource to pull the Helm chart from Artifactory
- Replace all environment variables in
values.ymlwith their values from the
- Perform the
helm upgradecommand to deploy the
simplehelmDockerImagefrom the Docker repository to a Kubernetes cluster
Note that the Image resource is not required by HelmDeploy to be in its
inputresources. The only resource HelmDeploy requires is a HelmChart.
simplehelmDockerImage so that its
imageTag properties are available to the step as environment variables. This enables the HelmDeploy step to perform the replacements of those environment variables in the
values.yml file of the Helm chart.
After the replacement, the
values.yml used by Helm might appear as (if this was run 1):
HelmDeploy from a Git Repository
We recommend pushing your Helm charts to Artifactory with traceable metadata,. However, the HelmDeploy step can use a Helm chart directly from a Git source repository instead.
To deploy using the Helm chart in the Git repository without pushing it to Artifactory:
- Skip the HelmPublish step
- In the Pipelines DSL for the
deploy_helm_chartstep, in the
inputresourcessection replace the
simplehelmChartHelmChart resource with the
The operation will produce the same result, including the replacement of environment variables in
For your reference, here is the complete Pipelines DSL for the example pipeline.