Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Helm cheat sheet to the help on helm commands

Installation and setup

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
helm version
helm repo add stable https://kubernetes-charts.storage.googleapis.com/

helm search and install app

helm search repo nginx
helm install stable/nginx-ingress   --generate-name
helm list

create application chart

helm create myapp
myapp]# tree
.
├── charts
├── Chart.yaml
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── hpa.yaml
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── serviceaccount.yaml
│   ├── service.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

3 directories, 10 files

install chart from chart directory

helm install myapp-stable ./myapp

NAME: myrelease
LAST DEPLOYED: Fri May 15 19:11:42 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=myapp,app.kubernetes.io/instance=myrelease" -o jsonpath="{.items[0].metadata.name}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace default port-forward $POD_NAME 8080:80

helm status

helm status myrelease

NAME: myrelease
LAST DEPLOYED: Fri May 15 19:20:02 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=myapp,app.kubernetes.io/instance=myrelease" -o jsonpath="{.items[0].metadata.name}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace default port-forward $POD_NAME 8080:80


 helm list
 NAME     	NAMESPACE	REVISION	UPDATED                                	STATUS  	CHART      	APP VERSION
 myrelease	default  	1       	2020-05-15 19:11:42.925874015 +0000 UTC	deployed	myapp-0.1.0	1.16.0

some advance usage

helm install myrelease ./myapp --set image.tag=stable

helm install myrelease ./myapp --set image.tag=stable -f custom-values.yaml

upgrade a release

helm upgrade myrelease

rollback a release to previous VERSION

helm rollback myrelease 1

uninstall

helm delete myrelease

Helm value validation

helm template myapp

helm lint myapp/
==> Linting myapp/
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed

Helm cache and config location

helm env 

tree ~/.cache/helm/

/root/.cache/helm/
└── repository
    ├── mysql-1.6.3.tgz
    ├── nginx-ingress-1.36.3.tgz
    ├── stable-charts.txt
    └── stable-index.yaml

1 directory, 4 files


tree ~/.config/helm/

/root/.config/helm/
├── repositories.lock
└── repositories.yaml

0 directories, 2 files

Creating a Chart with the help of deployment descriptor yaml

mkdir myapp1
cp myapp/Chart.yaml myapp1/
vim myapp1/Chart.yaml -- change app name
cat myapp1/Chart.yaml | grep name
name: myapp1

kubectl create deploy mynginx --image nginx --dry-run -o yaml > myapp1/templates/deployment.yaml

cd myapp1

helm install  mynginx .
NAME: mynginx
LAST DEPLOYED: Fri May 15 20:11:52 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

helm list
NAME     	NAMESPACE	REVISION	UPDATED                                	STATUS  	CHART       	APP VERSION
mynginx  	default  	1       	2020-05-15 20:11:52.951391012 +0000 UTC	deployed	myapp1-0.1.0	1.16.0     


kubectl expose deploy mynginx --port 80 --dry-run -o yaml
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: mynginx
    app.kubernetes.io/managed-by: Helm
  name: mynginx
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: mynginx
status:
  loadBalancer: {}

#### write to the template
kubectl expose deploy mynginx --port 80 --dry-run -o yaml > ~/myapp1/templates/service.yaml

#### update version in Chart.yaml
grep version Chart.yaml
version: 0.2.0

#### helm upgrade
helm upgrade mynginx .
Release "mynginx" has been upgraded. Happy Helming!
NAME: mynginx
LAST DEPLOYED: Fri May 15 20:19:23 2020
NAMESPACE: default
STATUS: deployed
REVISION: 2
TEST SUITE: None


you can further inhance mynginx chart by adding values in CHART_HOME/Chart.yaml and templatize the /myapp1/templates/service.yaml and /myapp1/templates/deployment.yaml to get the value source dynamically from the values.yaml


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment