I’m trying to learn k3s by deploying a simple nginx app where I use configmaps as a volume to mount my index.html
file.
# Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world-nginx
spec:
selector:
matchLabels:
app: hello-world
replicas: 1
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: hello-world-volume
mountPath: /usr/share/nginx/html
volumes:
- name: hello-world-volume
configMap:
name: hello-world
---
# Service
apiVersion: v1
kind: Service
metadata:
name: hello-world-service
spec:
ports:
- port: 80
protocol: TCP
selector:
app: hello-world
---
# Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hello-world
annotations:
spec.ingressClassName: "traefik"
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hello-world-service
port:
number: 80
This seems to work but when I add more replicas replicas: 3
. If I keep refreshing the page, I would get the output I expected 1 out of 3 but 2 out of 3 times, I get a Bad Gateway
error.