Create and Publish your helm chart in Gitlab


Creating Your Own Charts

  1. The Chart Development Guide explains how to develop your own charts. But you can get started quickly by using the helm create command:
helm create mychart
  1. Now there is a chart in ./mychart. You can edit it and create your own templates.

  2. As you edit your chart, you can validate that it is well-formed by running helm lint.

helm lint mychart
  1. When it’s time to package the chart up for distribution, you can run the helm package command:
helm install mychart ./mychart-0.1.0.tgz
  1. And that chart can now easily be installed by helm install:

Publish a package

Once built, a chart can be uploaded to the desired channel with curl or helm cm-push:

  • $USERNAME: the GitLab username or the deploy token username.
  • $ACCESS_TOKEN: the personal access token or the deploy token.
  • $PROJECT_ID: the project ID (like 43417816).
  • $CHANNEL: the name of the channel (like stable).

Note: To authenticate to the Helm repository, you need either:

With curl

export USERNAME=myusername
export ACCESS_TOKEN=mytoken
export PROJECT_ID=myprojectid
export CHANNEL=mychannel

# With curl
curl --request POST \
	--form '[email protected]' \
	--user $USERNAME:$ACCESS_TOKEN \
https://gitlab.example.com/api/v4/projects/$PROJECT_ID/packages/helm/api/$CHANNEL/charts

With the helm cm-push plugin

Install the Plugin:

helm plugin install https://github.com/chartmuseum/helm-push

Add repository, then push a chart to your repository

export USERNAME=myusername
export ACCESS_TOKEN=mytoken
export PROJECT_ID=myprojectid
export CHANNEL=stable
export PROJECT_NAME=partner-lab-docs
# With the helm cm-push plugin
helm repo add --username $USERNAME --password $ACCESS_TOKEN $PROJECT_NAME https://gitlab.com/api/v4/projects/$PROJECT_ID/packages/helm/$CHANNEL

helm cm-push mychart-0.1.0.tgz $PROJECT_NAME

Use CI/CD to publish a Helm package

To publish a Helm package automated through GitLab CI/CD, you can use CI_JOB_TOKEN in place of the personal access token in your commands.

image: curlimages/curl:latest

stages:
  - upload

upload:
  stage: upload
  script:
    - 'curl --request POST --user gitlab-ci-token:$CI_JOB_TOKEN --form "[email protected]" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/helm/api/<channel>/charts"'

References

Read more in the Helm documentation about these topics:

comments powered byDisqus