How to deploy application on Kubernetes with Helm

In this blog post I present step-by-step how to deploy multiple applications on Kubernetes cluster using Helm.

Photo by Andrew Neel on Unsplash
$ helm install stable/prometheus
$ helm create example
Creating example
$ minikube start😄  minikube v1.8.1 on Ubuntu 18.04
✨ Automatically selected the docker driver
🔥 Creating Kubernetes in docker container with (CPUs=2) (8 available), Memory=2200MB (7826MB available) ...
🐳 Preparing Kubernetes v1.17.3 on Docker 19.03.2 ...
▪ kubeadm.pod-network-cidr=10.244.0.0/16
❌ Unable to load cached images: loading cached images: stat /home/wojtek/.minikube/cache/images/k8s.gcr.io/kube-proxy_v1.17.3: no such file or directory
🚀 Launching Kubernetes ...
🌟 Enabling addons: default-storageclass, storage-provisioner
⌛ Waiting for cluster to come online ...
🏄 Done! kubectl is now configured to use "minikube"
$ minikube addons enable ingress
🌟 The 'ingress' addon is enabled
172.17.0.2  adminer.k8s.com
172.17.0.2 kanban.k8s.com
$ minikube ip
172.17.0.2
$ helm create postgres
Creating postgres
postgres:
name: postgres
postgres:
name: postgres
container:
image: postgres:9.6-alpine
postgres:
config:
data:
- key: key
value: value
replicaCount: 1postgres:
name: postgres
group: db
container:
image: postgres:9.6-alpine
port: 5432
service:
type: ClusterIP
port: 5432
volume:
name: postgres-storage
kind: PersistentVolumeClaim
mountPath: /var/lib/postgresql/data
pvc:
name: postgres-persistent-volume-claim
accessMode: ReadWriteOnce
storage: 4Gi
config:
name: postgres-config
data:
- key: key
value: value
postgres:
config:
data:
- key: POSTGRES_DB
value: kanban
- key: POSTGRES_USER
value: kanban
- key: POSTGRES_PASSWORD
value: kanban
$ helm install -f kanban-postgres.yaml postgres ./postgres
NAME: postgres
LAST DEPLOYED: Mon Apr 13 16:13:16 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
$ helm list
NAME NAMESPACE REVISION STATUS CHART APP VERSION
postgres default 1 deployed postgres-0.1.0 1.16.0
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
postgres 1/1 1 1 2m14s
$ helm create app
Creating app
app:
name: app
group: app
replicaCount: 1
container:
image: add-image-here
port: 8080
config: []
env:
- key: key
value: value
service:
type: ClusterIP
port: 8080
$ helm install -f adminer.yaml adminer ./app
NAME: adminer
LAST DEPLOYED: Mon Apr 13 16:57:17 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
$ helm install -f kanban-app.yaml kanban-app ./app
NAME: kanban-app
LAST DEPLOYED: Mon Apr 13 16:57:36 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
$ helm install -f kanban-ui.yaml kanban-ui ./app
NAME: kanban-ui
LAST DEPLOYED: Mon Apr 13 16:57:54 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
$ helm list
NAME NAMESPACE REVISION STATUS CHART APP VERSION
adminer default 1 deployed app-0.1.0 1.16.0
kanban-app default 1 deployed app-0.1.0 1.16.0
kanban-ui default 1 deployed app-0.1.0 1.16.0
postgres default 1 deployed postgres-0.1.0 1.16.0
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
adminer 1/1 1 1 112s
kanban-app 1/1 1 1 93s
kanban-ui 1/1 1 1 75s
postgres 1/1 1 1 45m
$ helm create ingress
Creating ingress
$ helm dependency update ./ingress/
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈Happy Helming!⎈
Saving 1 charts
Downloading nginx-ingress from repo https://kubernetes-charts.storage.googleapis.com/
Deleting outdated charts
$ helm install -f ingress.yaml ingress ./ingress
NAME: ingress
LAST DEPLOYED: Tue Apr 14 07:22:44 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
$ helm list
NAME NAMESPACE REVISION STATUS CHART APP VERSION
adminer default 1 deployed app-0.1.0 1.16.0
ingress default 1 deployed ingress-0.1.0 1.16.0
kanban-app default 1 deployed app-0.1.0 1.16.0
kanban-ui default 1 deployed app-0.1.0 1.16.0
postgres default 1 deployed postgres-0.1.0 1.16.0
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE
adminer 1/1 1 1
ingress-nginx-ingress-controller 1/1 1 1
ingress-nginx-ingress-default-backend 1/1 1 1
kanban-app 1/1 1 1
kanban-ui 1/1 1 1
postgres 1/1 1 1

Conclusions

In this short entry I’ve presented how, with Helm, you can reduce of copy-pasting tasks and can bring a one single template for deploying multiple applications on a Kubernetes cluster, which might be very handy in a microservice world. I hope you’ve enjoyed it.

Java Software Developer, DevOps newbie, constant learner, podcast enthusiast.