Reputation: 1044
I'm learning writing helm charts, specifically using range to iterate over a list in the values.yml and deploy multiple deployments. Maybe someone can understand what I'm doing wrong with this deployment of multiple mysql services. I've tried both node port and load balancer to no avail from my host machine (mac). With nodeport I get a connection refused against the node IP. With load balancer, I can telnet to the LB ip address and mysql port, but not connect with mysql. The connection hangs.
values.yaml
instances:
mysql01:
port: 30061
mysql02:
port: 30062
mysql03:
port: 30063
image:
name: mysql
tag: 5.7
service.yaml
{{- range $key, $value := .Values.instances }}
---
apiVersion: v1
kind: Service
metadata:
name: service-{{ $key }}
labels:
name: service-{{ $key }}
spec:
type: LoadBalancer
ports:
- port: 3306
targetPort: 3306
nodePort: {{ .port }}
protocol: "TCP"
selector:
name: {{ $key }}
{{- end }}
deployment.yaml
{{- range $key, $value := .Values.instances }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $key }}
labels:
app: {{ $key }}
spec:
selector:
matchLabels:
app: {{ $key }}
strategy:
type: Recreate
template:
metadata:
labels:
app: {{ $key }}
spec:
containers:
- image: {{ required "Please set image.name" $.Values.image.name }}:{{ required "Please set image.tag" $.Values.image.tag }}
name: {{ $key }}
env:
- name: MYSQL_ROOT_PASSWORD
value: password-{{ $key }}
livenessProbe:
tcpSocket:
port: 3306
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: persistent-storage-{{ $key }}
mountPath: /var/lib/mysql
volumes:
- name: persistent-storage-{{ $key }}
persistentVolumeClaim:
claimName: pv-claim-{{ $key }}
{{- end }}
Upvotes: 0
Views: 603
Reputation: 1044
I sorted this. It was the selector on the service, it was set as:
selector:
name: {{ $key }}
Should have been:
selector:
app: {{ $key }}
Upvotes: 1