Reputation:
How can I write kubernetes readiness probe for my spring boot application, which takes around 20 second to startup ? I tried to follow example from Configure Liveness, Readiness and Startup Probes, but I'm not sure how does Kubernetes figure out status code 200 as success
apiVersion: v1
kind: Pod
metadata:
labels:
app: backend
name: liveness-http
spec:
containers:
- name: liveness
image: k8s.gcr.io/liveness
args:
- /server
livenessProbe:
httpGet:
path: /healthz
port: 8080
httpHeaders:
- name: Custom-Header
value: Awesome
initialDelaySeconds: 3
periodSeconds: 3
Upvotes: 3
Views: 1538
Reputation: 1
K8 engine considers response code 200-399 as a successful probe. In your case you can add initial delay seconds for your probe to start with a delay of 20 seconds.
Upvotes: 0
Reputation: 44687
Kubernetes kubelet will make a http request at /healthz
path in your application and expects http status code 200 returned from that endpoint for the probe to be successful. So you need to have a rest endpoint in a rest controller which will return 200 from /healthz
. An easy way to achieve it would be to include spring boot actuator dependency and change the liveness probe path to /actuator/health/liveness
. Spring boot actuator by default comes with a rest controller endpoint which returns 200 from /actuator/health/liveness
.
Upvotes: 4
Reputation: 3604
initialDelaySeconds
field tells the kubelet that it should wait 20 seconds before performing the first probe. So this is generally configured to the value/time that the container / pod takes to start.
Configure initialDelaySeconds: 20
with the value as 20 seconds.
Upvotes: 3