Helm Practice Commands

Helm Practice Commands

Deployment of Nginx with Helm

Before we proceed make sure your EKS Cluster is upfront and running cd Hello

$ helm create hello

$ tree hello

$ cd hello
$ cat Chart.yaml

Chart.yaml contains metadata of the Helm

apiVersion: v2 #mandatory
name: hello #mandatory
description: A Helm chart for Kubernetes
type: application
version: 0.1.0 #mandatory
appVersion: 1.16.0

values.yaml

This file holds the values for the configuration, here you need to update the configuration at three places repository, port and service

  1. repository: nginx

  2. port: 80

  3. Service: NodePort

  4. Replicas count as needed

Change the service type to NodePort and the port is already set to 80

$ cd template
$ vi deployment.yaml          # No changes required for nginx 
$ vi service.yaml             # No changes required for nginx
$ cd

Template Command returns you will service.yaml, deployment.yaml and test-connection.yaml with actual value

$ helm template hello
$ helm lint hello              # Identifies the issues in yaml

As you can see the command output 1 chart(s) linted, 0 chart(s) failed. So there is no failure and you are good to go.

helm -debug -dry-run

Debug dry run is used to test the configuration before running our actual install command

$ helm install hello --debug --dry-run hello

helm install

$ helm install mynginx hello
$ helm list -a                       # List downs our helm releases

Here mynginx is the release name of the helm chart, Helm will generate its release name if we do not provide any and hello will be our actual chart name.

$ kubectl get all
# Gives us the complete imformation about the helm release

We have installed our first helm chart of the nginx application. Let's test the nginx application by accessing it.

WorkerNodePublicIP:NodePortIP

Upgrade helm release

Upgrade helps us to apply the new changes from yaml file

let's change the replica count in values.yaml file and use the upgrade command

Change the replica count from 3 to 4 in values.yaml

We need to run the upgrade command inside the hello

Pods got updated to 4 replicas.

Rollback Helm release

we upgraded the Helm chart release from version 1 to version 2

This feature rollbacks to the older version

$ helm rollback mynginx 1

See rollback revised back to version 1 where we have replicas as 3 Pods.


Pass environment variables into Helm Chart?

$ helm create helloworld
$ helm install helloworld-1 helloworld

By default the values.yaml file will have a replica count of 1.

Here we will be providing the replicas for our helm chart at runtime.

Let us delete our existing helm release

$ helm delete helloworld-1

Below command will install a release named helloworld-1 with replica as 2

 $ helm install --set replicaCount=2 helloworld-1 helloworld

We can also override the replicas 2 to 3 by using --set replicaCount command

Here I am using a new release name because you cannot use the same release name

$ helm install --set replicaCount=2 --set replicaCount=3 helloworld-2 helloworld


values.yaml

First, create myvalues.yaml

$ vi myvalues.yaml

Here we are updating the replicaCount in myvalues.yaml and applying it to the release name of the chart at installation

replicaCount: 3
$ helm create hi
$ helm install -f myvalues.yaml <releasename> <Chartname>
$ helm install -f myvalues.yaml myrelease rj


Iterate over key-value map

vi env-values.yaml

examplemap:
 - name: "USERNAME"
   value: "test1"
 - name: "PASSWORD"
   value: "test2"

To iterate or loop over the map first we need to create a place holder inside the Helm template.

Here are my placeholders

env:
    {{- range .Values.examplemap }}
    - name: {{ .name }}
      value: {{ .value }}
    {{- end }}

This is how my deployment.yaml would look like after putting the placeholder

$ helm template -f env-values.yaml helloworld

Helm overriding values.yaml with another values-override.yaml

$ helm create java

$ helm install javarelease java

Updating the replicas to 2

$ vi myvalues.yaml

replicaCount: 2

$ helm install -f myvalues.yaml javarelease1 java

$ kubectl get deployment

$vi myvalues-override.yaml

replicaCount: 3

$ helm install -f myvalues.yaml -f myvalues-override.yaml javarelease2 java

$ kubectl get deployment

Delete Helm release

$ helm delete <releasename>