Skip to content

Commit 280ac2e

Browse files
committed
Create helm-demo.md
1 parent f439321 commit 280ac2e

File tree

1 file changed

+201
-0
lines changed

1 file changed

+201
-0
lines changed

Diff for: package-managers/helm/helm-demo.md

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
## Helm demo
2+
*This demo will user the ingress on bare-metal using the Nginx Ingress Controller and metalLB.*
3+
4+
In my `helm-demo` folder, I have the `templates` directory and the `Chart` and `values` YAML files :
5+
```bash
6+
k8s-master@master:~/helm-demo$ ls
7+
Chart.yaml templates values.yaml
8+
```
9+
Inside the Chart.yaml file :
10+
```YAML
11+
name: my-first-demo
12+
version: 1.0.0
13+
description: easy helm demo
14+
maintainers:
15+
- name: Siwar
16+
```
17+
This is the metadata to describe each deployment.
18+
19+
Now inside the templates directory :
20+
```bash
21+
k8s-master@master:~/helm-demo/templates$ ls
22+
deployment.yaml ingress.yaml service.yaml
23+
```
24+
The depoyment.yaml file contains a simple nginx deployment :
25+
```YAML
26+
apiVersion: apps/v1
27+
kind: Deployment
28+
metadata:
29+
name: my-nginx-deployment
30+
spec:
31+
selector:
32+
matchLabels:
33+
app: nginx
34+
replicas: 3
35+
template:
36+
metadata:
37+
labels:
38+
app: nginx
39+
spec:
40+
containers:
41+
- name: nginx
42+
image: nginx:1.14.2
43+
ports:
44+
- containerPort: 80
45+
46+
```
47+
And the service.yaml file :
48+
``` YAML
49+
apiVersion: v1
50+
kind: Service
51+
metadata:
52+
name: my-nginx-service
53+
spec:
54+
selector:
55+
app: nginx
56+
ports:
57+
- name: main
58+
protocol: TCP
59+
port: 80
60+
```
61+
And the ingress.yaml :
62+
```YAML
63+
apiVersion: networking.k8s.io/v1
64+
kind: Ingress
65+
metadata:
66+
name: my-nginx-ingress
67+
annotations:
68+
nginx.ingress.kubernetes.io/rewrite-target: /
69+
http.port: "443"
70+
spec:
71+
ingressClassName: nginx
72+
rules:
73+
- http:
74+
paths:
75+
- path: /testpath
76+
pathType: Prefix
77+
backend:
78+
service:
79+
name: my-nginx-service
80+
port:
81+
number: 80
82+
83+
```
84+
We're exposing port 443 on our ingress.
85+
86+
Next is `helm install`:
87+
```bash
88+
k8s-master@master:~$ helm install --generate-name helm-demo/
89+
NAME: helm-demo-1660310990
90+
LAST DEPLOYED: Fri Aug 12 06:29:50 2022
91+
NAMESPACE: default
92+
STATUS: deployed
93+
REVISION: 1
94+
TEST SUITE: None
95+
```
96+
So now with Helm and thanks to only one command line tool `helm install`, we were able to deploy our app very easily and very fast.
97+
```bash
98+
k8s-master@master:~$ kubectl get all
99+
NAME READY STATUS RESTARTS AGE
100+
pod/my-nginx-deployment-9456bbbf9-c74rs 0/1 ContainerCreating 0 11s
101+
pod/my-nginx-deployment-9456bbbf9-k4cdb 0/1 ContainerCreating 0 11s
102+
pod/my-nginx-deployment-9456bbbf9-mm7dm 0/1 ContainerCreating 0 11s
103+
104+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
105+
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 22m
106+
service/my-nginx-service ClusterIP 10.100.146.193 <none> 80/TCP 11s
107+
108+
NAME READY UP-TO-DATE AVAILABLE AGE
109+
deployment.apps/my-nginx-deployment 0/3 3 0 11s
110+
111+
NAME DESIRED CURRENT READY AGE
112+
replicaset.apps/my-nginx-deployment-9456bbbf9 3 3 0 11s
113+
```
114+
We can check our app running in the browser using the ingress ip `192.168.1.240` and specifying the path `/testpath`:
115+
116+
<img src="nginx.png" width=50% height=50%>
117+
118+
The usual way to do this with kubectl is by executing the `kubectl apply` command line for every resource.
119+
120+
Another important feature in Helm are placeholders!
121+
so if we look at another deployment.yaml file for example :
122+
```Yaml
123+
apiVersion: apps/v1
124+
kind: Deployment
125+
metadata:
126+
name: my-nginx-deployment
127+
spec:
128+
selector:
129+
matchLabels:
130+
app: nginx
131+
replicas: {{.Values.scale}}
132+
template:
133+
metadata:
134+
labels:
135+
app: nginx
136+
spec:
137+
containers:
138+
- name: nginx
139+
image: nginx:1.14.2
140+
ports:
141+
- containerPort: 80
142+
```
143+
The `{{.Values.scale}}`placeholder makes it possible to modify the configuration without having to edit the actual manifest file every time.
144+
145+
So whatever the value of scale is in `values.yaml` file is going to be the value of the configuration file.
146+
147+
The `values.yaml` file :
148+
```bash
149+
k8s-master@master:~/helming-once-more$ cat values.yaml
150+
scale: 3
151+
```
152+
153+
And now let's install our app again :
154+
```bash
155+
k8s-master@master:~$ helm install another-demo helming-once-more/
156+
NAME: another-demo
157+
LAST DEPLOYED: Fri Aug 12 11:48:53 2022
158+
NAMESPACE: default
159+
STATUS: deployed
160+
REVISION: 1
161+
TEST SUITE: None
162+
```
163+
Just to check that we have our pods up and running :
164+
```bash
165+
k8s-master@master:~$ kubectl get pods
166+
NAME READY STATUS RESTARTS AGE
167+
my-nginx-deployment-9456bbbf9-mx45n 1/1 Running 0 3m9s
168+
my-nginx-deployment-9456bbbf9-rqkmw 1/1 Running 0 3m9s
169+
my-nginx-deployment-9456bbbf9-tl4wj 1/1 Running 0 3m9s
170+
```
171+
So thanks to the scale value in the values.yaml file, we now have 3 pods.
172+
173+
For some reason or another, we needed to scale up our up :
174+
```bash
175+
k8s-master@master:~$ helm upgrade --set scale=5 another-demo ./helming-once-more/
176+
Release "another-demo" has been upgraded. Happy Helming!
177+
NAME: another-demo
178+
LAST DEPLOYED: Fri Aug 12 11:55:14 2022
179+
NAMESPACE: default
180+
STATUS: deployed
181+
REVISION: 2
182+
TEST SUITE: None
183+
```
184+
```bash
185+
k8s-master@master:~$ kubectl get pod
186+
NAME READY STATUS RESTARTS AGE
187+
my-nginx-deployment-9456bbbf9-7ddlm 1/1 Running 0 95s
188+
my-nginx-deployment-9456bbbf9-mx45n 1/1 Running 0 8m9s
189+
my-nginx-deployment-9456bbbf9-rqkmw 1/1 Running 0 8m9s
190+
my-nginx-deployment-9456bbbf9-tl4wj 1/1 Running 0 8m9s
191+
my-nginx-deployment-9456bbbf9-tpsqv 1/1 Running 0 96s
192+
```
193+
194+
To finish off, we will delete our app :
195+
```bash
196+
k8s-master@master:~$ helm list
197+
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
198+
another-demo default 2 2022-08-12 11:55:14.913503686 -0700 PDT deployed another-demo-1.0.0
199+
k8s-master@master:~$ helm uninstall another-demo
200+
release "another-demo" uninstalled
201+
```

0 commit comments

Comments
 (0)