Skip to content

Commit fd9e2a4

Browse files
authored
Merge pull request #39 from Bit-Developer/deploy-with-helm-template
Deploy with helm template
2 parents 8aa8708 + 3d44916 commit fd9e2a4

6 files changed

Lines changed: 101 additions & 11 deletions

File tree

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,83 @@ Start the service to view the web app in brower.
100100
minikube service compare-helm
101101
```
102102

103+
# Use helm with template
104+
105+
## Use values.yaml
106+
107+
Edit the file in `template` folder, use `Values` variables and put the actual values in `values.yaml`.
108+
109+
```yaml
110+
appName: compare-helm
111+
namespace: default
112+
113+
configmap:
114+
name: compare-configmap
115+
data:
116+
ENV_NAME: 'DEV'
117+
118+
image:
119+
name: jojozhuang/text-compare-angular
120+
tag: latest
121+
```
122+
123+
Upgrade the deployment.
124+
125+
```sh
126+
helm upgrade compare-helm deployment --values deployment/values.yaml
127+
W0107 21:30:02.019806 39661 warnings.go:70] unknown field "spec.ports[0].type"
128+
Release "compare-helm" has been upgraded. Happy Helming!
129+
NAME: compare-helm
130+
LAST DEPLOYED: Sun Jan 7 21:30:01 2024
131+
NAMESPACE: default
132+
STATUS: deployed
133+
REVISION: 3
134+
TEST SUITE: None
135+
```
136+
137+
After each upgrade, the revision number should be incremented.
138+
139+
```sh
140+
helm ls
141+
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
142+
compare-helm default 5 2024-01-07 21:38:03.669554 -0800 PST deployed deployment-0.1.0 1.16.0
143+
```
144+
145+
## Add notes
146+
147+
Create file `NOTES.txt` under `deployment/templates` directory with the following content.
148+
149+
```sh
150+
servicename=$(k get service -l "app={{ .Values.appName }}" -o jsonpath="{.items[0].metadata.name}")
151+
kubectl --namespace {{ .Values.namespace}} port-forward service/{{ .Values.appName }} 8888:80
152+
```
153+
154+
Each time when you run the upgrade command, you will see the notes in the output.
155+
156+
```sh
157+
helm upgrade compare-helm deployment --values deployment/values.yaml
158+
W0107 21:49:34.774115 40283 warnings.go:70] unknown field "spec.ports[0].type"
159+
Release "compare-helm" has been upgraded. Happy Helming!
160+
NAME: compare-helm
161+
LAST DEPLOYED: Sun Jan 7 21:49:34 2024
162+
NAMESPACE: default
163+
STATUS: deployed
164+
REVISION: 6
165+
TEST SUITE: None
166+
NOTES:
167+
servicename=$(k get service -l "app=compare-helm" -o jsonpath="{.items[0].metadata.name}")
168+
kubectl --namespace default port-forward service/compare-helm 8888:80
169+
```
170+
171+
Copy and paste the two lines and execute them in teminal.
172+
173+
```sh
174+
servicename=$(k get service -l "app=compare-helm" -o jsonpath="{.items[0].metadata.name}")
175+
kubectl --namespace default port-forward service/compare-helm 8888:80
176+
```
177+
178+
Then, you are able to access your site through `http://localhost:8888/`.
179+
103180
- [How to Create Helm Charts - The Ultimate Guide](https://www.youtube.com/watch?v=jUYNS90nq8U&ab_channel=DevOpsJourney)
104181

105182
# Deployment

deployment/templates/NOTES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
servicename=$(k get service -l "app={{ .Values.appName }}" -o jsonpath="{.items[0].metadata.name}")
2+
kubectl --namespace {{ .Values.namespace}} port-forward service/{{ .Values.appName }} 8888:80
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v1
22
kind: ConfigMap
33
metadata:
4-
name: compare-configmap
5-
#namespace: bit-developer
4+
name: {{ .Values.configmap.name }}
5+
namespace: {{ .Values.namespace }}
66
data:
7-
ENV_NAME: 'DEV'
7+
ENV_NAME: {{ .Values.configmap.data.ENV_NAME }}

deployment/templates/service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
kind: Service
33
metadata:
44
name: compare-helm
5-
#namespace: bit-developer
5+
namespace: {{ .Values.namespace }}
66
labels:
77
app: compare-helm
88
spec:

deployment/templates/text-compare.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
apiVersion: apps/v1
22
kind: Deployment
33
metadata:
4-
name: compare-helm
5-
#namespace: bit-developer
4+
name: {{ .Values.appName }}
5+
namespace: {{ .Values.namespace }}
66
labels:
7-
app: compare-helm
7+
app: {{ .Values.appName }}
88
spec:
99
replicas: 1
1010
selector:
1111
matchLabels:
12-
app: compare-helm
12+
app: {{ .Values.appName }}
1313
tier: frontend
1414
template:
1515
metadata:
1616
labels:
17-
app: compare-helm
17+
app: {{ .Values.appName }}
1818
tier: frontend
1919
spec: # Pod spec
2020
containers:
21-
- name: compare-helm
22-
image: jojozhuang/text-compare-angular
21+
- name: {{ .Values.appName }}
22+
image: "{{ .Values.image.name }}:{{ .Values.image.tag }}"
2323
ports:
2424
- containerPort: 80
2525
resources:

deployment/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
appName: compare-helm
2+
namespace: default
3+
4+
configmap:
5+
name: compare-configmap
6+
data:
7+
ENV_NAME: 'DEV'
8+
9+
image:
10+
name: jojozhuang/text-compare-angular
11+
tag: latest

0 commit comments

Comments
 (0)