Please visit to my helm blog to understand the concept of helm.
https://siddharathadhumale.blogspot.com/2021/04/understanding-of-helm-and-its-use-case.html
https://siddharathadhumale.blogspot.com/2021/04/simple-helm-example-for-kubernetes-with.html
In the above blog we had shown how springboot microservice communicate with each other in side Kubernetes env using docker as container.
For that we had written 3 yaml file one for namespace, one for producer springboot and one for consumer springboot.
Now lets used the flavour of helm and create the helm chart that will deploy both our springboot microservice and create namespace.
Helm is really handy for the developer. As you know if we are working with Kubernetes we have to create many yaml files for concept like deployment, role, statefulset, deamonset, pod, volume, configmap, secrets, ingress, node, container, rolebinding, operator, service, service account (Dr-Sd-PVC-SIN-CROSS )to configure K8 env. Furthermore these things need to be executed in sequence i.e. secreate need to be created first so that we can use them in config map and so on. It becomes really difficult to track all this things in seqence when the application level increase. To overcome this helm comes handy. It act as an package manager for Kubernetes…let me try to explain as we have apt, npm, homebrew which are package manager same way we can collect all the yaml and package them in to once chart and upload it on helm repository (private or public). Further, any developer can easily use this package and execute it using helm command to make sure that all the things that is mandate is present and executed in sequence manner for K8 setup.
So lets begin … As stated earlier as i am using windows O/S and minikube is giving me 100% disk usage I moved to use K8 with docker desktop with below configuration.
Let check we have clear base K8 enviroment i.e no namespace except default and no pod and service is running.
Make sure you have helm installed using below command
Step 1:- Create helm chart:
exeute follwing commands
helm create siddhu-ms-k8-doc-helm-chart
C:\vscode-helm-workspace\siddhu-ms-k8-docker-helm-chart>helm create siddhu-ms-k8-doc-helm-chart
Creating siddhu-ms-k8-doc-helm-chart
C:\vscode-helm-workspace\siddhu-ms-k8-docker-helm-chart>
C:\vscode-helm-workspace\siddhu-ms-k8-docker-helm-chart>tree siddhu-ms-k8-doc-helm-chart /F
Folder PATH listing
Volume serial number is 287F-B791
C:\VSCODE-HELM-WORKSPACE\SIDDHU-MS-K8-DOCKER-HELM-CHART\SIDDHU-MS-K8-DOC-HELM-CHART
│ .helmignore
│ Chart.yaml
│ values.yaml
│
├───charts
└───templates
│ deployment.yaml
│ hpa.yaml
│ ingress.yaml
│ NOTES.txt
│ service.yaml
│ serviceaccount.yaml
│ _helpers.tpl
│
└───tests
test-connection.yaml
we have two folder chart and template and two files chart and value.yaml files
Chart.yaml :- this file contains some information like chart version, name , its dependencies i.e. in short it contains meta data for the chart.
Values.yaml :- this files contains configuration template values that can be used in the tempalate applicaiton specific yaml files. This are default values and we can override it later.
charts/ :- this folder contains depenencies that myChartName has. i.e. if we create a chart that is used to deploy elastic stake but in depth it depends on some XYZ chart used to install addition package such as transection,persistant etc.
template/ :- this is the folder that contains all the template files that used to install/update application in K8 cluster using yaml. It will contains the values that is configured in values/yaml files.
Remove all files from template folder.Now lets modifiy the required files.
Create following files as shown below :-
Note you can download the same from my github location given at the end of this blog.
make following files
1- siddhu-namespace.yaml
1 2 3 4 | kind: Namespace apiVersion: v1 metadata: name: {{ .Values.namespace.name }} |
2- springboot-docker-producer.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | apiVersion: apps/v1 kind: Deployment metadata: name: {{ .Values.springbootdockerproducerdeployment.name }} namespace: {{ .Values.namespace.name }} spec: selector: matchLabels: component: {{ .Values.springbootdockerproducerdeployment.name }} template: metadata: labels: component: {{ .Values.springbootdockerproducerdeployment.name }} spec: containers: - name: springboot-docker-producer image: {{ .Values.producerimage.repository }}:{{ .Values.producerimage.tag | default .Chart.AppVersion }} env: - name: discovery.type value: single-node ports: - containerPort: {{ .Values.springbootproducer.port }} name: http protocol: TCP --- apiVersion: v1 kind: Service metadata: name: siddhuproducer namespace: {{ .Values.namespace.name }} labels: service: {{ .Values.springbootdockerproducerdeployment.name }} spec: type: NodePort selector: component: {{ .Values.springbootdockerproducerdeployment.name }} ports: - port: {{ .Values.producerservice.port }} targetPort: {{ .Values.producerservice.targetPort }} |
3- springboot-docker-consumer.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | apiVersion: apps/v1 kind: Deployment metadata: name: {{ .Values.springbootdockerconsumerdeployment.name }} namespace: {{ .Values.namespace.name }} spec: selector: matchLabels: component: {{ .Values.springbootdockerconsumerdeployment.name }} template: metadata: labels: component: {{ .Values.springbootdockerconsumerdeployment.name }} spec: containers: - name: {{ .Values.springbootdockerconsumerdeployment.name }} image: {{ .Values.consumerimage.repository }}:{{ .Values.consumerimage.tag | default .Chart.AppVersion }} env: - name: discovery.type value: single-node ports: - containerPort: {{ .Values.springbootconsumer.port }} name: http protocol: TCP --- apiVersion: v1 kind: Service metadata: name: siddhuconsumer namespace: {{ .Values.namespace.name }} labels: service: {{ .Values.springbootdockerconsumerdeployment.name }} spec: type: {{ .Values.service.type }} selector: component: {{ .Values.springbootdockerconsumerdeployment.name }} ports: - port: {{ .Values.service.port }} targetPort: {{ .Values.service.targetPort }} |
4- Make follwoing changes in values.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | # Default values for siddhu-ms-k8-doc-helm-chart. # This is a YAML-formatted file. # Declare variables to be passed into your templates. replicaCount: 1 #by siddhu start[ namespace: name: springboot-application springbootdockerproducerdeployment: name: springboot-docker-producer producerimage: repository: shdhumale/springboot-docker-producer # Overrides the image tag whose default is the chart appVersion. tag: "latest" springbootproducer: port: 8091 producerservice: type: NodePort #by siddhu give the nodeport so that we can access it from out side. port: 8091 #by siddhu expose to node targetPort: 8091 #by siddhu App server listening on this port containerPort: 8091 springbootdockerconsumerdeployment: name: springboot-docker-consumer consumerimage: repository: shdhumale/springboot-docker-consumer # Overrides the image tag whose default is the chart appVersion. tag: "latest" springbootconsumer: port: 8090 service: type: NodePort #by siddhu give the nodeport so that we can access it from out side. port: 8090 #by siddhu expose to node targetPort: 8090 #by siddhu App server listening on this port containerPort: 8090 #by siddhu start] |
now lets run below command and check if all yaml file is created properly
C:\vscode-helm-workspace\siddhu-ms-k8-docker-helm-chart>helm template siddhu-ms-k8-doc-helm-chart >> helmcreatedyaml.yaml
We will find that all the component that is needed is create properly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | --- # Source: siddhu-ms-k8-doc-helm-chart/templates/siddhu-namespace.yaml kind: Namespace apiVersion: v1 metadata: name: springboot-application --- # Source: siddhu-ms-k8-doc-helm-chart/templates/springboot-docker-consumer.yaml apiVersion: v1 kind: Service metadata: name: siddhuconsumer namespace: springboot-application labels: service: springboot-docker-consumer spec: type: NodePort selector: component: springboot-docker-consumer ports: - port: 8090 targetPort: 8090 --- # Source: siddhu-ms-k8-doc-helm-chart/templates/springboot-docker-producer.yaml apiVersion: v1 kind: Service metadata: name: siddhuproducer namespace: springboot-application labels: service: springboot-docker-producer spec: type: NodePort selector: component: springboot-docker-producer ports: - port: 8091 targetPort: 8091 --- # Source: siddhu-ms-k8-doc-helm-chart/templates/springboot-docker-consumer.yaml apiVersion: apps/v1 kind: Deployment metadata: name: springboot-docker-consumer namespace: springboot-application spec: selector: matchLabels: component: springboot-docker-consumer template: metadata: labels: component: springboot-docker-consumer spec: containers: - name: springboot-docker-consumer image: shdhumale/springboot-docker-consumer:latest env: - name: discovery.type value: single-node ports: - containerPort: 8090 name: http protocol: TCP --- # Source: siddhu-ms-k8-doc-helm-chart/templates/springboot-docker-producer.yaml apiVersion: apps/v1 kind: Deployment metadata: name: springboot-docker-producer namespace: springboot-application spec: selector: matchLabels: component: springboot-docker-producer template: metadata: labels: component: springboot-docker-producer spec: containers: - name: springboot-docker-producer image: shdhumale/springboot-docker-producer:latest env: - name: discovery.type value: single-node ports: - containerPort: 8091 name: http protocol: TCP --- # Source: siddhu-ms-k8-doc-helm-chart/templates/tests/test-connection.yaml apiVersion: v1 kind: Pod metadata: name: "RELEASE-NAME-siddhu-ms-k8-doc-helm-chart-test-connection" labels: helm.sh/chart: siddhu-ms-k8-doc-helm-chart-0.1.0 app.kubernetes.io/name: siddhu-ms-k8-doc-helm-chart app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/version: "1.16.0" app.kubernetes.io/managed-by: Helm annotations: "helm.sh/hook": test spec: containers: - name: wget image: busybox command: ['wget'] args: ['RELEASE-NAME-siddhu-ms-k8-doc-helm-chart:8090'] restartPolicy: Never |
Also try to run helm lint command lint provided by helm which you could run to identify possible issues forehand.
C:\vscode-helm-workspace\siddhu-ms-k8-docker-helm-chart>helm lint siddhu-ms-k8-doc-helm-chart
==> Linting siddhu-ms-k8-doc-helm-chart
[INFO] Chart.yaml: icon is recommended
1 chart(s) linted, 0 chart(s) failed
C:\vscode-helm-workspace\siddhu-ms-k8-docker-helm-chart>
As shown above we did not get any error.
Now let use the helm command -dry-run. this allows developer to test its configuration before running the final install command
Use the following -dry-run command to verify our siddhu-ms-k8-doc-helm-chart Helm Chart
helm install siddhu-ms-k8-doc-helm-chart –-debug –-dry-run siddhu-ms-k8-doc-helm-chart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | C:\vscode-helm-workspace\siddhu-ms-k8-docker-helm-chart>helm install siddhu-ms-k8-doc-helm-chart --debug --dry-run siddhu-ms-k8-doc-helm-chart install.go:173: [debug] Original chart version: "" install.go:190: [debug] CHART PATH: C:\vscode-helm-workspace\siddhu-ms-k8-docker-helm-chart\siddhu-ms-k8-doc-helm-chart NAME: siddhu-ms-k8-doc-helm-chart LAST DEPLOYED: Thu Jun 17 14:42:55 2021 NAMESPACE: default STATUS: pending-install REVISION: 1 USER-SUPPLIED VALUES: {} COMPUTED VALUES: consumerimage: repository: shdhumale/springboot-docker-consumer tag: latest namespace: name: springboot-application producerimage: repository: shdhumale/springboot-docker-producer tag: latest producerservice: containerPort: 8091 port: 8091 targetPort: 8091 type: NodePort replicaCount: 1 service: containerPort: 8090 port: 8090 targetPort: 8090 type: NodePort springbootconsumer: port: 8090 springbootdockerconsumerdeployment: name: springboot-docker-consumer springbootdockerproducerdeployment: name: springboot-docker-producer springbootproducer: port: 8091 HOOKS: --- # Source: siddhu-ms-k8-doc-helm-chart/templates/tests/test-connection.yaml apiVersion: v1 kind: Pod metadata: name: "siddhu-ms-k8-doc-helm-chart-test-connection" labels: helm.sh/chart: siddhu-ms-k8-doc-helm-chart-0.1.0 app.kubernetes.io/name: siddhu-ms-k8-doc-helm-chart app.kubernetes.io/instance: siddhu-ms-k8-doc-helm-chart app.kubernetes.io/version: "1.16.0" app.kubernetes.io/managed-by: Helm annotations: "helm.sh/hook": test spec: containers: - name: wget image: busybox command: ['wget'] args: ['siddhu-ms-k8-doc-helm-chart:8090'] restartPolicy: Never MANIFEST: --- # Source: siddhu-ms-k8-doc-helm-chart/templates/siddhu-namespace.yaml kind: Namespace apiVersion: v1 metadata: name: springboot-application --- # Source: siddhu-ms-k8-doc-helm-chart/templates/springboot-docker-consumer.yaml apiVersion: v1 kind: Service metadata: name: siddhuconsumer namespace: springboot-application labels: service: springboot-docker-consumer spec: type: NodePort selector: component: springboot-docker-consumer ports: - port: 8090 targetPort: 8090 --- # Source: siddhu-ms-k8-doc-helm-chart/templates/springboot-docker-producer.yaml apiVersion: v1 kind: Service metadata: name: siddhuproducer namespace: springboot-application labels: service: springboot-docker-producer spec: type: NodePort selector: component: springboot-docker-producer ports: - port: 8091 targetPort: 8091 --- # Source: siddhu-ms-k8-doc-helm-chart/templates/springboot-docker-consumer.yaml apiVersion: apps/v1 kind: Deployment metadata: name: springboot-docker-consumer namespace: springboot-application spec: selector: matchLabels: component: springboot-docker-consumer template: metadata: labels: component: springboot-docker-consumer spec: containers: - name: springboot-docker-consumer image: shdhumale/springboot-docker-consumer:latest env: - name: discovery.type value: single-node ports: - containerPort: 8090 name: http protocol: TCP --- # Source: siddhu-ms-k8-doc-helm-chart/templates/springboot-docker-producer.yaml apiVersion: apps/v1 kind: Deployment metadata: name: springboot-docker-producer namespace: springboot-application spec: selector: matchLabels: component: springboot-docker-producer template: metadata: labels: component: springboot-docker-producer spec: containers: - name: springboot-docker-producer image: shdhumale/springboot-docker-producer:latest env: - name: discovery.type value: single-node ports: - containerPort: 8091 name: http protocol: TCP |
Now finally we are ready to install our helm char using below command and lets check all is working fine.
helm install siddhu-ms-k8-doc-helm-chart siddhu-ms-k8-doc-helm-chart
1 2 3 4 5 6 7 8 | C:\vscode-helm-workspace\siddhu-ms-k8-docker-helm-chart>helm install siddhu-ms-k8-doc-helm-chart siddhu-ms-k8-doc-helm-chart NAME: siddhu-ms-k8-doc-helm-chart LAST DEPLOYED: Thu Jun 17 14:44:31 2021 NAMESPACE: default STATUS: deployed REVISION: 1 C:\vscode-helm-workspace\siddhu-ms-k8-docker-helm-chart> |
now finally check we got all thing created properly as shown below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | C:\vscode-helm-workspace\siddhu-ms-k8-docker-helm-chart>kubectl get all -n springboot-application -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pod/springboot-docker-consumer-69cd4b98f-p5v7b 1/1 Running 0 4m17s 10.1.0.29 docker-desktop <none> <none> pod/springboot-docker-producer-6866686c74-bnxhs 1/1 Running 0 4m17s 10.1.0.30 docker-desktop <none> <none> NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR service/siddhuconsumer NodePort 10.101.75.8 <none> 8090:30624/TCP 4m17s component=springboot-docker-consumer service/siddhuproducer NodePort 10.96.239.92 <none> 8091:31971/TCP 4m18s component=springboot-docker-producer NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR deployment.apps/springboot-docker-consumer 1/1 1 1 4m17s springboot-docker-consumer shdhumale/springboot-docker-consumer:latest component=springboot-docker-consumer deployment.apps/springboot-docker-producer 1/1 1 1 4m17s springboot-docker-producer shdhumale/springboot-docker-producer:latest component=springboot-docker-producer NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR replicaset.apps/springboot-docker-consumer-69cd4b98f 1 1 1 4m17s springboot-docker-consumer shdhumale/springboot-docker-consumer:latest component=springboot-docker-consumer,pod-template-hash=69cd4b98f replicaset.apps/springboot-docker-producer-6866686c74 1 1 1 4m17s springboot-docker-producer shdhumale/springboot-docker-producer:latest component=springboot-docker-producer,pod-template-hash=6866686c74 |
finally do port-forward for our both producer and consumer applicaiton as shown below and check url if it is working.
C:\vscode-helm-workspace\siddhu-ms-k8-docker-helm-chart>kubectl port-forward springboot-docker-producer-6866686c74-bnxhs 8091:8091 -n springboot-application
Forwarding from 127.0.0.1:8091 -> 8091
Forwarding from [::1]:8091 -> 8091
C:\vscode-helm-workspace\siddhu-ms-k8-docker-helm-chart>kubectl port-forward springboot-docker-producer-6866686c74-bnxhs 8091:8091 -n springboot-application
Forwarding from 127.0.0.1:8091 -> 8091
Forwarding from [::1]:8091 -> 8091
Handling connection for 8091
Note: Download the heml chart yaml from below location.
https://github.com/shdhumale/springboot-docker-consumer.git
No comments:
Post a Comment