<p>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 <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/" rel="nofollow noreferrer">Configure Liveness, Readiness and Startup Probes</a>, but I'm not sure how does Kubernetes figure out status code 200 as success </p>

<pre><code>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
</code></pre>

<p>Kubernetes kubelet will make a http request at <code>/healthz</code> 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 <code>/healthz</code>. An easy way to achieve it would be to include spring boot actuator dependency and change the liveness probe path to <code>/actuator/health/liveness</code>. Spring boot actuator by default comes with a rest controller endpoint which returns 200 from <code>/actuator/health/liveness</code>.</p>

<p><a href="https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-kubernetes-probes" rel="nofollow noreferrer">https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-kubernetes-probes</a></p>
