A GitHub action to run helm chart deployments operations.
- Setup your environment. More information.
- Add the required
KUBECTL_CONFIG
andCHART_VALUES
secrets to the environment. - Add this action as a step on your deployment workflow.
Both secrets most be properly encoded in base64.
cat values.yml | base64
name
: Deployment name. Required.namespace
: Kubernetes namespace used for the deployment. Required.version
: Specific application version to deploy. Will be used as image tag. Works with or without thev
prefix, for example0.1.0
orv0.1.0
charts
: Relative path to the charts inside the repository. (defaults tohelm/*
)atomic
: The deployment process rolls back changes made in case of error.no-hooks
: Prevent hooks from running during install.force
: Force resource updates through a replacement strategy.timeout
: Time to wait for any individual Kubernetes operations. (defaults to5m0s
)
Sample step configuration.
steps:
- name: Helm chart deployment
uses: bryk-io/chart-deploy-action@v1.2.0
# example with all parameters
with:
name: my-deployment # required
namespace: dev # required
version: v0.1.0 # optional
charts: deploy/my-chart # optional
atomic: yes # optional
no-hooks: yes # optional
force: yes # optional
timeout: 8m30s # optional
env:
KUBECTL_CONFIG: ${{ secrets.KUBECTL_CONFIG }} # required
CHART_VALUES: ${{ secrets.CHART_VALUES }} # required
Note: For the
version
parameter to work properly, the chart must support the valueimage.tag
orimage.version
and use it to adjust the container image being deployed. For example:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion | trimPrefix "v" }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
Sample workflow file.
name: deploy-dev
on:
# To manually run deployments
workflow_dispatch: {}
# To automatically run deployments for tagged releases
push:
tags:
- '*'
jobs:
# Deploy helm chart
deploy:
name: run deployment
runs-on: ubuntu-latest
timeout-minutes: 10
# Using a specific environment
environment: dev
steps:
# Checkout code
- name: Checkout repository
uses: actions/checkout@v3
# Deploy chart
- name: Helm chart deployment
uses: bryk-io/chart-deploy-action@v1.2.0
with:
name: my-deployment
namespace: dev
env:
KUBECTL_CONFIG: ${{ secrets.KUBECTL_CONFIG }}
CHART_VALUES: ${{ secrets.CHART_VALUES }}
To manually trigger this workflow using GitHub's CLI tool.
gh workflow run deploy-dev
Setting up and using GitHub environments is recommended but not required to use this action. Alternatively you can use a single workflow and combination of Kubernetes namespaces to manage isolated deployments. There are some pros and cons to this approach to consider though.
- Only a single workflow file is required to be enabled on the repository.
- The secrets used to configure a specific namespace can then be managed at the organization level and shared across several projects simplifying administration.
- You'll loose integration with GitHub's UI for deployments, and potentially related features and tooling released in the future.
- Create a Kubernetes namespace for the environment you wanna use for the deployment.
For example
dev
. - Create organization or repository secrets to hold the Kubectl configuration and specific
chart values. Name the secrets using the specific namespace as prefix, for example:
KUBECTL_CONFIG_DEV
andCHART_VALUES_DEV
. - Use this action with proper values for the required parameters.
Sample workflow file.
name: deploy
on:
# Manual deployment
workflow_dispatch:
inputs:
deployment:
description: 'Deployment name'
required: true
default: 'echo-server'
namespace:
description: 'Kubernetes namespace to deploy into'
required: true
version:
description: 'Specific application version to deploy (used as image tag)'
required: false
default: ''
jobs:
deploy:
name: run deployment
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
# Checkout code
- name: Checkout repository
uses: actions/checkout@v3
# Deploy chart
- name: Helm chart deployment
uses: bryk-io/chart-deploy-action@v1.2.0
with:
name: ${{ github.event.inputs.deployment }}
namespace: ${{ github.event.inputs.namespace }}
version: ${{ github.event.inputs.version }}
env:
# Use the name space as prefix to load the required secrets
KUBECTL_CONFIG: ${{ secrets[format('kubectl_config_{0}', github.event.inputs.namespace)] }}
CHART_VALUES: ${{ secrets[format('chart_values_{0}', github.event.inputs.namespace)] }}
To manually trigger this workflow using GitHub's CLI tool.
gh workflow run deploy -f deployment=echo-server -f namespace=dev