How to Deploy With Helm in Bitbucket Pipelines
Run helm upgrade --install with --atomic --wait so the release is rolled back automatically if the new pods never become ready.
Helm makes a Kubernetes deploy a single declarative command. Pass the new image tag with --set, and use --atomic so a failed upgrade reverts to the previous revision instead of leaving the release broken.
Steps
- Provide cluster access (kubeconfig from a secured variable).
- Run
helm upgrade --install <release> <chart>with--set image.tag=<tag>. - Add
--atomic --wait --timeout 5mso failures roll back cleanly. - Optionally
helm historyafter to confirm the new revision.
Pipeline
bitbucket-pipelines.yml
image: alpine/helm:3.15.2
pipelines:
branches:
main:
- step:
name: Helm deploy
deployment: production
script:
- mkdir -p $HOME/.kube && echo "$KUBECONFIG_B64" | base64 -d > $HOME/.kube/config
- >
helm upgrade --install web ./charts/web
--namespace prod
--set image.repository=$IMAGE_REPO
--set image.tag=$BITBUCKET_COMMIT
--atomic --wait --timeout 5m
- helm history web -n prod --max 3Gotchas
--atomicimplies--wait; if pods do not become ready in--timeout, Helm rolls back.- Pin the Helm image tag so a chart that worked yesterday is not broken by a Helm major bump.
- Keep secrets out of
--seton the command line; use--valueswith a secured file.
Related guides
How to Deploy to EKS and Kubernetes With Bitbucket PipelinesDeploy to an EKS or any Kubernetes cluster from Bitbucket Pipelines by writing a kubeconfig from a secured va…
How to Roll Back a Deploy With Bitbucket PipelinesRoll back a bad release from Bitbucket Pipelines with a custom pipeline that takes a target version as a vari…