Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,83 @@ Start the service to view the web app in brower.
minikube service compare-helm
```

# Use helm with template

## Use values.yaml

Edit the file in `template` folder, use `Values` variables and put the actual values in `values.yaml`.

```yaml
appName: compare-helm
namespace: default

configmap:
name: compare-configmap
data:
ENV_NAME: 'DEV'

image:
name: jojozhuang/text-compare-angular
tag: latest
```

Upgrade the deployment.

```sh
helm upgrade compare-helm deployment --values deployment/values.yaml
W0107 21:30:02.019806 39661 warnings.go:70] unknown field "spec.ports[0].type"
Release "compare-helm" has been upgraded. Happy Helming!
NAME: compare-helm
LAST DEPLOYED: Sun Jan 7 21:30:01 2024
NAMESPACE: default
STATUS: deployed
REVISION: 3
TEST SUITE: None
```

After each upgrade, the revision number should be incremented.

```sh
helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
compare-helm default 5 2024-01-07 21:38:03.669554 -0800 PST deployed deployment-0.1.0 1.16.0
```

## Add notes

Create file `NOTES.txt` under `deployment/templates` directory with the following content.

```sh
servicename=$(k get service -l "app={{ .Values.appName }}" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace {{ .Values.namespace}} port-forward service/{{ .Values.appName }} 8888:80
```

Each time when you run the upgrade command, you will see the notes in the output.

```sh
helm upgrade compare-helm deployment --values deployment/values.yaml
W0107 21:49:34.774115 40283 warnings.go:70] unknown field "spec.ports[0].type"
Release "compare-helm" has been upgraded. Happy Helming!
NAME: compare-helm
LAST DEPLOYED: Sun Jan 7 21:49:34 2024
NAMESPACE: default
STATUS: deployed
REVISION: 6
TEST SUITE: None
NOTES:
servicename=$(k get service -l "app=compare-helm" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace default port-forward service/compare-helm 8888:80
```

Copy and paste the two lines and execute them in teminal.

```sh
servicename=$(k get service -l "app=compare-helm" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace default port-forward service/compare-helm 8888:80
```

Then, you are able to access your site through `http://localhost:8888/`.

- [How to Create Helm Charts - The Ultimate Guide](https://www.youtube.com/watch?v=jUYNS90nq8U&ab_channel=DevOpsJourney)

# Deployment
Expand Down
2 changes: 2 additions & 0 deletions deployment/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
servicename=$(k get service -l "app={{ .Values.appName }}" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace {{ .Values.namespace}} port-forward service/{{ .Values.appName }} 8888:80
6 changes: 3 additions & 3 deletions deployment/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: compare-configmap
#namespace: bit-developer
name: {{ .Values.configmap.name }}
namespace: {{ .Values.namespace }}
data:
ENV_NAME: 'DEV'
ENV_NAME: {{ .Values.configmap.data.ENV_NAME }}
2 changes: 1 addition & 1 deletion deployment/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: compare-helm
#namespace: bit-developer
namespace: {{ .Values.namespace }}
labels:
app: compare-helm
spec:
Expand Down
14 changes: 7 additions & 7 deletions deployment/templates/text-compare.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: compare-helm
#namespace: bit-developer
name: {{ .Values.appName }}
namespace: {{ .Values.namespace }}
labels:
app: compare-helm
app: {{ .Values.appName }}
spec:
replicas: 1
selector:
matchLabels:
app: compare-helm
app: {{ .Values.appName }}
tier: frontend
template:
metadata:
labels:
app: compare-helm
app: {{ .Values.appName }}
tier: frontend
spec: # Pod spec
containers:
- name: compare-helm
image: jojozhuang/text-compare-angular
- name: {{ .Values.appName }}
image: "{{ .Values.image.name }}:{{ .Values.image.tag }}"
ports:
- containerPort: 80
resources:
Expand Down
11 changes: 11 additions & 0 deletions deployment/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
appName: compare-helm
namespace: default

configmap:
name: compare-configmap
data:
ENV_NAME: 'DEV'

image:
name: jojozhuang/text-compare-angular
tag: latest