-
Notifications
You must be signed in to change notification settings - Fork 7
Helm_Lab_05 | Functions
Abhishek Dubey edited this page Dec 11, 2020
·
11 revisions
The Purpose of this lab is to give the understanding of existing functions in helm
Till now we have used the templating feature of the helm, but now we would like to know how we can have more programmatic control over the helm chart.Let's start by adding if and else statement for liveness and readiness probe. In which the liveness and readiness probe will only get applied if it is enabled
- Update the gowebapp/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: goweb-app
labels:
app.kubernetes.io/name: app
app.kubernetes.io/instance: goweb-app
app.kubernetes.io/version: "1.16.0"
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: app
app.kubernetes.io/instance: goweb-app
template:
metadata:
labels:
app.kubernetes.io/name: app
app.kubernetes.io/instance: goweb-app
spec:
containers:
- name: {{ .Values.containers.name }}
image: "{{ .Values.containers.image }}:{{ .Values.containers.tag }}"
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 8080
protocol: TCP
env:
- name: DB_URL
value: goweb-app-mysql
- name: DB_PORT
value: "3306"
- name: DB_USER
value: "root"
- name: DB_PASSWORD
value: password
- name: REDIS_HOST
value: "goweb-app-redis-headless"
- name: REDIS_PORT
value: "6379"
{{- if .Values.containers.livenessProbe.enabled }}
livenessProbe:
tcpSocket:
port: {{ int .Values.containers.livenessProbe.tcpSocket.port }}
initialDelaySeconds: 5
periodSeconds: 5
{{- end }}
{{- if .Values.containers.readinessProbe.enabled }}
readinessProbe:
tcpSocket:
port: {{ int .Values.containers.readinessProbe.tcpSocket.port }}
initialDelaySeconds: 5
periodSeconds: 5
{{- end }}
- Update the gowebapp/values.yaml file
mysql:
mysqlDatabase: employeedb
mysqlRootPassword: password
persistence:
enabled: false
redis:
usePassword: false
cluster:
enabled: false
master:
persistence:
enabled: false
containers:
name: gowebapp
image: opstreedevops/ot-go-webapp
tag: "v1"
livenessProbe:
enabled: true
tcpSocket:
port: 8080
readinessProbe:
enabled: true
tcpSocket:
port: 8080
Let's add with block to change scope of helm
- Update the gowebapp/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: goweb-app
labels:
app.kubernetes.io/name: app
app.kubernetes.io/instance: goweb-app
app.kubernetes.io/version: "1.16.0"
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: app
app.kubernetes.io/instance: goweb-app
template:
metadata:
labels:
app.kubernetes.io/name: app
app.kubernetes.io/instance: goweb-app
spec:
containers:
- name: {{ .Values.containers.name }}
image: "{{ .Values.containers.image }}:{{ .Values.containers.tag }}"
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 8080
protocol: TCP
env:
- name: DB_URL
value: goweb-app-mysql
- name: DB_PORT
value: "3306"
- name: DB_USER
value: "root"
- name: DB_PASSWORD
value: password
- name: REDIS_HOST
value: "goweb-app-redis-headless"
- name: REDIS_PORT
value: "6379"
{{- if .Values.containers.livenessProbe }}
{{- with .Values.containers.livenessProbe }}
{{- toYaml . | nindent 10 }}
{{- end }}
{{- end }}
{{- if .Values.containers.readinessProbe }}
{{- with .Values.containers.readinessProbe }}
{{- toYaml . | nindent 10 }}
{{- end }}
{{- end }}
- Update the gowebapp/values.yaml file
mysql:
mysqlDatabase: employeedb
mysqlRootPassword: password
persistence:
enabled: false
redis:
usePassword: false
cluster:
enabled: false
master:
persistence:
enabled: false
containers:
name: gowebapp
image: opstreedevops/ot-go-webapp
tag: "v1"
livenessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 5
periodSeconds: 5