Helm Chart App in Kubernetes using AWS ec2 instances
What is Helm? In simple terms, Helm is a package manager for Kubernetes. Helm is the K8s equivalent of yum or apt. Helm deploys charts, which you can think of as a packaged application. It is a collection of all your versioned, pre-configured application resources which can be deployed as one unit.
What is my plan?
My plan is to create my own customize chart App in kubernetes. And as helm is a package manager tool used to install chart( packages) in kubernetes, so i will first install helm in Master Node (currently my workspace) and then create chart app.
Let’s follow below steps to achieve our plan.
Launch four instances of ec2, one for Master and 3 for worker nodes:
Using my pre-default configuration of kubernetes AMI in AWS:
Ec2-instances launched successfully:
Login to Master Node :
Initialize the Master Node:
kubeadm init — pod-network-cidr=10.244.0.0/16 — ignore-preflight-errors=all
Refer to official documentation of Node Initialization: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/
Or you can use of one of my brother write-up on Multi-node Cluster setup here: https://florientdogbe.medium.com/setting-up-kubernetes-multi-node-cluster-on-the-top-of-amazon-ec2-instance-7d3e11336381?source=follow_footer---------0----------------------------
Three workers node joining the Master Node with:
kubeadm join 172.31.40.22:6443 — token <token generated from Master Node> — node-name node1
Same thing with others nodes
Install helm Package Manager in my Master Node:
Typing: helm in my command shows that
i haven’t install it so let’s do that.
“ To install Helm know that i will go for the binary for more cmds practical😁. Also know that Helm is a client program which come with 2 differents versions if you want to install it . The Version 2 older one run a program call Tiller which manage client/server access to your kubernetes cluster. And the new version3 remove that functionality with client/library.”
I will so go for the latest version 3 of Helm .
Doc for helm installation=> https://helm.sh/docs/intro/install/
- Install Helm with “wget https://get.helm.sh/helm-v3.5.2-linux-amd64.tar.gz” command from github repository as i will download the binary package.
Decompress the file with : tar -xvzf <download_helm_file>
cp linux-amd64/helm /usr/bin
helm version => to check the setup is successfull
Now the main party comes here how to create custom package/ chart in kubernetes ?
If you create custom package we have to write small programs, and we need a workspace in which we will create program; so to that i will create a workspace “ws-helm”. Also one thing to remember is the fact that your package name will take the folder name in which they reside , this means for each program i will create one folder for that.
Let’s do it now 😊
- For example you can create 3 folders, one for each package/chart:
- One Chart “myweb” related to all my web program files, “mysql-db” for all the files required to my database mysql and one folder for integration development “jenkins”.
- Time to write web chart file:
Note: The chart file name start with Capital “C” and has “yaml” extension like: Chart.yaml
After creating the Chart config file you have install it with helm like: helm install <app_name> <folder_of _your_Chart>
To check the successfully installed app do: helm list
- One thing before continue is, we have to create a folder “templates” which will contains all the resources, pods, pv.yaml files we have to launch: To do it “mkdir templates”
- Now Inside this template folder, create a deployment file like:
Link to the docker repository for deployment image: https://hub.docker.com/repository/docker/tcdocker2021/ubuntu-nginx-server
I dont’ know if you understand my plan till here ? I want the package manger will handle all pods or deployments i would like to deploy or launch , so for that apart the fact of creating the Chart file i have also to create a template folder in which all resources, pods, deployments will reside. So now the Chart app will launch for us the deployment , let’s do it:
- Now install the app by helm like:
And now you can see that our Chart app by helm launched a deployment for us.
Let’s create a service file for our Chart app in templates folder with : kubectl expose deploy mydeploy — port=80 — type=NodePort — dry-run -o yaml > service.yaml
- And from the above output, you can see that we only have kubernetes services launched, so let’s launch loadbalancer service through Chart App:
- Now as we have already created the app and now we want to add more resources, we have to update the version of our app like:
Change the version of app and upgrade with :
helm upgrade <app_name> <mypackage_name>
Helm list => And now our app has been upgraded
And load Balancer service launched also:
- let’s practice more😁 by updating our deployment by increasing the replicas to three:
- And upgrade the version of our app to 0.3:
helm upgrade web-app myweb/ : to update the Chart app
- Now let’s see the case we want to parametrize our deployment so that instead of writing every time in deployment file, we can set a file in which we set the count value of our replicas:
- For that let’s create a variable file called “values.yaml” in app folder like:
- Inside this file we set the number of replicas of our deployment pods like:
- After now go to deployment file to add this values.yaml file as a parameter of replicas:
- Again install the app through helm: helm install <app_name> <package_folder>:
Note: You can set the replicas also while installing the app like: helm install <web-app_name> <folder_package>/ — set replicaCount=<no_of_replicas_you_want>
For more hands on practice, we can play do the same thing with service type of our pods by setting it in a variable file and go to the services file in template folder and parametrize the type of our service there.
So that is the way we can create our own Chart App in kubernetes with help of Helm Manager tool.
Keep Learning and see you in another story 👻