I have an application deployed to kubernetes. Here is techstack: Java 11, Spring Boot 2.3.x or 2.5.x, using hikari 3.x or 4.x
Using spring actuator to do healthcheck. Here is liveness and readiness configuration within application.yaml:
endpoint:
health:
group:
liveness:
include: '*'
exclude:
- db
- readinessState
readiness:
include: '*'
what it does if DB is down -
- Makes sure
livenessdoesn't get impacted - meaning, application container should keep on running even if there is DB outage. readinessswill be impacted making sure no traffic is allowed to hit the container.
liveness and readiness configuration in container spec:
livenessProbe:
httpGet:
path: actuator/health/liveness
port: 8443
scheme: HTTPS
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 5
readinessProbe:
httpGet:
path: actuator/health/readiness
port: 8443
scheme: HTTPS
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 20
My application is started and running fine for few hours.
What I did:
I brought down DB.
Issue Noticed:
When DB is down, after 90+ seconds I see 3 more pods getting spinned up. When a pod is described I see Status and condition like below:
Status: Running
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
when I list all running pods:
NAME READY STATUS RESTARTS AGE
application-a-dev-deployment-success-5d86b4bcf4-7lsqx 0/1 Running 0 6h48m
application-a-dev-deployment-success-5d86b4bcf4-cmwd7 0/1 Running 0 49m
application-a-dev-deployment-success-5d86b4bcf4-flf7r 0/1 Running 0 48m
application-a-dev-deployment-success-5d86b4bcf4-m5nk7 0/1 Running 0 6h48m
application-a-dev-deployment-success-5d86b4bcf4-tx4rl 0/1 Running 0 49m
My Analogy/Finding:
Per ReadinessProbe configuration: periodSeconds is set to 30 seconds and failurethreshold is defaulted to 3 per k8s documentation.
Per application.yaml readiness includes db check, meaning after every 30 seconds readiness check failed. When it fails 3 times, failurethreshold is met and it spins up new pods.
Restart policy is default to Always.
Questions:
- Why it spinned new pods?
- Why it spinned specifically only 3 pods and not 1 or 2 or 4 or any number?
- Does this has to do anything with
restartpolicy?