Working with Helm Charts
1. Installing Helm CLI
| Platform | Installation Method | Command | Notes |
|---|---|---|---|
| Linux (x86_64) | Package Manager | curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash |
Installs latest stable version |
| macOS | Homebrew | brew install helm |
Latest stable version from Homebrew |
| Windows | Chocolatey | choco install kubernetes-helm |
Installs Helm via Chocolatey package manager |
| Windows | Manual Download | curl -LO https://get.helm.sh/helm-v3.15.0-windows-amd64.zip |
Download and extract manually from Helm releases page |
| All Platforms | Binary Release | curl -LO https://get.helm.sh/helm-v3.15.0-linux-amd64.tar.gz |
Download tarball and extract helm binary |
Note: Helm requires
kubectl to be installed and configured for cluster access.
2. Adding Helm Repositories
| Command | Description | Options | Example |
|---|---|---|---|
| helm repo add | Add a new Helm repository | --ca-file, --cert-file, --key-file, --username, --password |
helm repo add stable https://charts.helm.sh/stable |
Note: The
stable repository is deprecated as of Helm 3.12.0 and should not be used for new installations.Warning: Adding repositories from untrusted sources can introduce security vulnerabilities.
Repository Management
- Use
helm repo addto register a new repository - Repositories are stored in
$HOME/.helm/repository(Helm v2) or$HOME/.config/helm/repositories.yaml(Helm v3) - Use
helm repo listto view registered repositories
3. Updating Helm Repositories
| Command | Description | Notes |
|---|---|---|
| helm repo update | Updates the list of charts from all configured repositories | Fetches latest chart metadata and updates local cache |
| helm repo update <repo-name> | Updates a specific repository by name | Useful for updating only one repository when multiple exist |
Note: The
helm repo update command refreshes the local cache of chart information from remote repositories. It does not install or upgrade charts, but ensures that the local Helm client has the most recent chart metadata.
4. Searching Helm Charts
| Command | Description | Flags |
|---|---|---|
| helm search repo | Search for charts in the configured repositories | --devel to include development charts--regexp REGEXP to filter by regex--version VERSION to specify version |
| helm search hub | Search for charts in Artifact Hub | --endpoint ENDPOINT to specify custom endpoint--filter FILTER to filter results by name or description--limit LIMIT to limit number of results |
5. Installing Helm Chart
| Option | Values | Description |
|---|---|---|
| --set | key=value |
Set values on the command line (can be used multiple times) |
| --values | values.yaml |
Specify values in a YAML file or URL |
| --namespace | my-namespace |
Namespace to install the release into |
| --create-namespace | true |
Create the namespace if it does not exist |
| --wait | true |
Wait for all resources to be ready before marking the release as successful |
| --timeout | 300s |
Time to wait for any individual Kubernetes operation (default 5m0s) |
Example: Installing a Helm Chart
helm install my-release stable/nginx-ingress \
--set controller.service.type=LoadBalancer \
--namespace production \
--create-namespace \
--wait
Note: The
helm install command creates a new release. If you want to upgrade an existing release, use helm upgrade.
Warning: Ensure that the namespace exists or use
--create-namespace to avoid errors during installation.
6. Upgrading Helm Release
| Command | Description | Options |
|---|---|---|
| helm upgrade | Upgrades a release to a new version of the chart | -i, --install - Install the release if not already installed--set - Set values on the command line--values, -f - Specify values in a YAML file or string |
Note: If the release is not installed, use
helm install instead of helm upgrade.
Warning: Ensure that the new chart version is compatible with the existing release to avoid unexpected behavior.
7. Rolling Back Release
| Command | Description | Notes |
|---|---|---|
| helm rollback <release-name> [<revision>] | Rollback a release to a previous revision | Reinstalls the specified release at a given revision |
Note: If no revision is specified, Helm rolls back to the previous release.
Warning: Rolling back may cause data loss if the previous revision had different configurations or resources.
| Flag | Description | Default |
|---|---|---|
| --debug | Enable debug output | false |
| --dry-run | Simulate a rollback without making changes | false |
| --recreate-pods | Recreate pods for resources that support it | false |
| --timeout | Time to wait for any individual Kubernetes operation | 5m0s |
| --wait | Wait for resources to be ready after rollback | false |
8. Listing Helm Releases
| Command | Description | Flags |
|---|---|---|
| helm list | List all Helm releases in the current namespace | -n, --namespace to specify a namespace-q, --short for concise output |
| helm list --all-namespaces | List all Helm releases across all namespaces | --all-namespaces or -A |
| helm list --deployed | List only deployed releases | --deployed |
| helm list --suppressed | List only suppressed releases | --suppressed |
| helm list --pending | List only pending releases | --pending |
| helm list --failed | List only failed releases | --failed |
Note: By default,
helm list shows only deployed releases. Use flags like --failed, --pending, or --suppressed to view other release statuses.
9. Viewing Release Values
| Command | Description | Example |
|---|---|---|
| helm get values | Fetches the values of a release | helm get values my-release |
| helm get values -a | Fetches all values including defaults | helm get values -a my-release |
| helm get values -o yaml | Outputs values in YAML format | helm get values -o yaml my-release |
Example: Fetching Release Values
helm get values my-release
# Output:
# database.host: mysql.example.com
# database.port: 3306
# database.name: myapp
Example: Fetching All Values Including Defaults
helm get values -a my-release
# Output:
# database.host: mysql.example.com
# database.port: 3306
# database.name: myapp
# database.username: admin
# database.password: secret
10. Uninstalling Helm Release
| Option | Values | Description |
|---|---|---|
| helm uninstall | RELEASE_NAME |
Uninstalls a Helm release by its name |
| --namespace | _NAMESPACE_ |
Specifies the namespace where the release is installed |
| --dry-run | true |
Simulates the uninstallation without making changes |
| --keep-history | true |
Retains release history after uninstallation |
Note: By default, Helm retains the release history. Use
--keep-history=false to delete history as well.
11. Creating Custom Chart
| File/Directory | Description | Notes |
|---|---|---|
| Chart.yaml | Chart metadata | Required file with name, version, appVersion, etc. |
| values.yaml | Default values for templates | Overrideable by users or CI/CD |
| templates/ | Template files | Contains Kubernetes manifests |
| templates/deployment.yaml | Deployment manifest | Example template using values |
| templates/service.yaml | Service manifest | Exposes the deployment |
| templates/_helpers.tpl | Helper templates | Reusable template snippets |
Example: Deployment Template
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "my-app.fullname" . }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "my-app.labels" . | nindent 8 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "my-app.labels" . | nindent 8 }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
ports:
- containerPort: {{ .Values.service.port }}
Note: Use
helm template to preview chart before installing.Warning: Avoid hardcoding values in templates; use
.Values instead.12. Using Helm Templating
| Feature | Description | Usage |
|---|---|---|
| .Release.Name | Release name of the Helm release | {{ .Release.Name }} |
| .Values | Values provided to the chart | {{ .Values.database.port }} |
| .Chart | Chart metadata (name, version) | {{ .Chart.Name }}-{{ .Chart.Version }} |
| .Files | Access to files in the chart | {{ .Files.Get "config.yaml" }} |
Example: Using .Values in a Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "myapp.fullname" . }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "myapp.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
ports:
- containerPort: {{ .Values.service.port }}
Example: Conditional Template with .Values
{{- if .Values.service.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "myapp.fullname" . }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.targetPort }}
{{- end }}
Note: Helm templates use Go template syntax. Always test your templates with
helm template before deploying.
Warning: Avoid complex logic in templates. Keep templates simple and readable.