So we can manually rollback a bad release, but wouldn’t it be nice if we could prevent this bad release from being released in the first place?
Kubernetes lets us define a way to automatically probe a pod before it starts receiving requests, and that’s what we can use in this case. There are two types of probes: a readinessProbe and a livenessProbe. We’ll first use readinessProbe, and then we can talk about the difference between the two.
Let’s go back to our manifest and add this readinessProbe attribute:
xxxxxxxxxx
apiVersion: apps/v1
kind: Deployment
metadata:
name: hellok8s
spec:
replicas: 2
selector:
matchLabels:
app: hellok8s
template:
metadata:
labels:
app: hellok8s
spec:
containers:
- image: brianstorti/hellok8s:v2 # Still using v2
name: hellok8s-container
readinessProbe: # New readiness probe
periodSeconds: 1
successThreshold: 5
httpGet:
path: /
port: 4567