I’m new to Kubernetes (K8S) and trying to learn how to achieve zero downtime during deployments. I have two services: currency-exchange
and currency-conversion
, where currency-conversion
depends on currency-exchange
.
When I deploy a new version of currency-exchange
, the old pod stops immediately, causing an internal server error since the new pod isn’t ready yet. To prevent this, I added Readiness and Liveness probes to the deployment YAML so that Kubernetes checks the pod’s health before terminating the old one. My understanding is that this should help maintain zero downtime.
The Issue: When I add both the Liveness and Readiness probes, the new pod fails to start correctly and enters a CrashLoopBackOff
state after multiple restarts.
this is my deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
labels:
app: currency-exchange
name: currency-exchange
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: currency-exchange
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: currency-exchange
spec:
containers:
- image: username_24/currency-exchange-service:0.0.11-SNAPSHOT
imagePullPolicy: IfNotPresent
name: mmv2-currency-exchange-service
readinessProbe:
httpGet:
port: 8000
path: /actuator/health/readiness
livenessProbe:
httpGet:
port: 8000
path: /actuator/health/liveness
resources:
limits:
cpu: 500m
ephemeral-storage: 1Gi
memory: 2Gi
requests:
cpu: 500m
ephemeral-storage: 1Gi
memory: 2Gi
restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
labels:
app: currency-exchange
name: currency-exchange
namespace: default
spec:
ports:
- port: 8000
protocol: TCP
targetPort: 8000
selector:
app: currency-exchange
sessionAffinity: None
type: LoadBalancer
this is the related props in the application.properties
## Activate the health probes (liveness and readiness) to avoid downtime
management.endpoint.health.probes.enabled=true
management.health.livenessState.enabled=true
management.health.readinessState.enabled=true
What I’ve Tried: I tried removing the Liveness probe and using only the Readiness probe. This seems to work fine, and there is no downtime during deployment. However, I need to understand why the pod fails and enters CrashLoopBackOff
when the Liveness probe is enabled.
Any insights into what might be going wrong or how to properly configure these probes to avoid downtime would be greatly appreciated!