Salta ai contenuti

Helm Commands

Helm is a package manager for Kubernetes that simplifies chart distribution and deployment.

Installation

macOS

# Homebrew
brew install helm

# From source
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

# Verify
helm version

Linux

# Download
wget https://get.helm.sh/helm-v3.12.0-linux-amd64.tar.gz
tar -zxvf helm-v3.12.0-linux-amd64.tar.gz
sudo mv linux-amd64/helm /usr/local/bin/

# Verify
helm version

Windows

# Chocolatey
choco install kubernetes-helm

# Scoop
scoop install helm

Basic Commands

CommandDescription
helm versionDisplay Helm version
helm helpShow help
helm repo listList configured repositories
helm search repo nginxSearch for chart
helm listList releases in current namespace
helm list -n kube-systemList releases in namespace

Repository Management

# Add repository
helm repo add bitnami https://charts.bitnami.com/bitnami

# Add with options
helm repo add myrepo https://example.com/charts \
  --username user \
  --password pass

# Update repository
helm repo update

# Remove repository
helm repo remove bitnami

# Search repositories
helm search repo nginx

# Show all versions
helm search repo nginx --versions

# Get repository list
helm repo list

Chart Installation

Basic Install

# Install from repository
helm install my-release bitnami/nginx

# Install with custom name
helm install my-nginx bitnami/nginx -n my-namespace --create-namespace

# Install from chart file
helm install my-release ./my-chart

# Install specific version
helm install my-release bitnami/nginx --version 13.1.5

# Install with values file
helm install my-release bitnami/nginx -f values.yaml

# Install with inline values
helm install my-release bitnami/nginx \
  --set replicaCount=3 \
  --set image.tag=latest

# Dry run
helm install my-release bitnami/nginx --dry-run --debug

# Install with wait
helm install my-release bitnami/nginx --wait --timeout 10m

Values Override

# Multiple values files
helm install my-release bitnami/nginx \
  -f values.yaml \
  -f values-production.yaml

# Override specific values
helm install my-release bitnami/nginx \
  --set service.type=LoadBalancer \
  --set persistence.enabled=true \
  --set persistence.size=10Gi \
  --set replicaCount=5

# Override nested values
helm install my-release bitnami/nginx \
  --set image.repository=myrepo/nginx \
  --set image.tag=1.20 \
  --set "postgresql.auth.password=mypass"

Release Management

Upgrade Releases

# Upgrade to latest chart version
helm upgrade my-release bitnami/nginx

# Upgrade with values
helm upgrade my-release bitnami/nginx \
  -f new-values.yaml

# Upgrade specific version
helm upgrade my-release bitnami/nginx --version 14.0.0

# Upgrade without changing values
helm upgrade my-release bitnami/nginx --reuse-values

# Upgrade with history
helm upgrade my-release bitnami/nginx --install --atomic

# Preview changes
helm upgrade my-release bitnami/nginx --dry-run --debug

Rollback Releases

# Rollback to previous release
helm rollback my-release

# Rollback to specific revision
helm rollback my-release 2

# Rollback with cleanup
helm rollback my-release --cleanup-on-fail

Manage Releases

# Get release status
helm status my-release

# Get release values
helm get values my-release

# Get release manifest
helm get manifest my-release

# Get all release info
helm get all my-release

# List release history
helm history my-release

# Uninstall release
helm uninstall my-release

# Uninstall with keep history
helm uninstall my-release --keep-history

Chart Operations

Create Charts

# Create new chart
helm create my-chart

# Chart structure
my-chart/
├── Chart.yaml
├── values.yaml
├── charts/
├── templates/
   ├── deployment.yaml
   ├── service.yaml
   ├── ingress.yaml
   ├── NOTES.txt
   └── _helpers.tpl
└── README.md

Chart Commands

# Lint chart for errors
helm lint my-chart

# Validate chart
helm lint my-chart --strict

# Template rendering
helm template my-release my-chart

# Render with values
helm template my-release my-chart -f values.yaml

# Package chart
helm package my-chart
# Creates: my-chart-1.0.0.tgz

# Inspect chart values
helm inspect values bitnami/nginx

# Inspect chart
helm show chart bitnami/nginx

# Get all chart info
helm show all bitnami/nginx

Working with Values

values.yaml Template

replicaCount: 1

image:
  repository: nginx
  tag: "1.20"
  pullPolicy: IfNotPresent

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  className: "nginx"
  hosts:
    - host: example.com
      paths:
        - path: /
          pathType: Prefix

resources:
  limits:
    cpu: 100m
    memory: 128Mi
  requests:
    cpu: 100m
    memory: 128Mi

nodeSelector: {}

tolerations: []

affinity: {}

persistence:
  enabled: false
  size: 1Gi
  storageClassName: "standard"

Chart Testing

# Helm test (if chart includes test pods)
helm test my-release

# Debug values
helm template my-release bitnami/nginx --debug

# Check templates
helm lint my-chart

# Verify install
helm install my-release my-chart --dry-run --debug

Dependency Management

Chart Dependencies (Chart.yaml)

dependencies:
  - name: postgresql
    version: "11.x.x"
    repository: "https://charts.bitnami.com/bitnami"
    condition: postgresql.enabled

Manage Dependencies

# Update dependencies
helm dependency update ./my-chart

# List dependencies
helm dependency list ./my-chart

# Build dependencies
helm dependency build ./my-chart

Advanced Features

Hooks

# Pre-install hook
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ include "mychart.fullname" . }}-pre-install
  annotations:
    "helm.sh/hook": pre-install
    "helm.sh/hook-weight": "0"
    "helm.sh/hook-delete-policy": before-hook-creation

Conditionals in Templates

{{ if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ include "chart.fullname" . }}
spec:
  rules:
    {{- range .Values.ingress.hosts }}
    - host: {{ .host }}
      http:
        paths:
          {{- range .paths }}
          - path: {{ .path }}
            backend:
              serviceName: {{ include "chart.fullname" . }}
              servicePort: {{ .Values.service.port }}
          {{- end }}
    {{- end }}
{{ end }}

Loops in Templates

{{- range $key, $value := .Values.config }}
{{ $key }}: {{ $value }}
{{- end }}

Repository Hosting

Create Repository

# Create index
helm repo index my-charts/

# Serve locally
python -m http.server --directory my-charts 8000

# Add local repo
helm repo add my-local http://localhost:8000

Plugin Management

# List plugins
helm plugin list

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

# Uninstall plugin
helm plugin uninstall push

Troubleshooting

# Check release status
helm status my-release -n default

# View release events
kubectl describe release my-release -n default

# Check pod status
kubectl get pods -l app=my-release

# View logs
kubectl logs -l app=my-release

# Debug template rendering
helm template my-release bitnami/nginx --debug

# Get hook status
kubectl get hooks -n default

Best Practices

  • Use semantic versioning for charts
  • Document values.yaml thoroughly
  • Implement linting checks
  • Use helpers for common patterns
  • Set resource requests/limits
  • Implement health checks (probes)
  • Use init containers for setup
  • Provide sensible defaults
  • Test charts before distribution
  • Version dependencies explicitly

Useful Flags

FlagPurpose
--namespaceKubernetes namespace
--create-namespaceCreate namespace if not exists
--waitWait for deployment
--timeoutTimeout duration
--atomicRollback on failure
--dry-runPreview without installing
--debugEnable debug output
--valuesOverride values file
--setOverride individual values
--versionSpecific chart version

Resources


Last updated: 2026-03-30|Helm 3.12+