Configure Kubernetes probes
The default liveness and readiness groups match the Kubernetes probes. Kubernetes treats any
HTTP status from 200 to 399 as success, so DOWN and OUT_OF_SERVICE (HTTP 503) count as
failures.
Add the probes
Section titled “Add the probes”spec: containers: - name: app image: my-app:1.4.2 ports: - containerPort: 8080 livenessProbe: httpGet: path: /actuator/health/liveness port: 8080 periodSeconds: 10 timeoutSeconds: 2 failureThreshold: 3 readinessProbe: httpGet: path: /actuator/health/readiness port: 8080 periodSeconds: 5 timeoutSeconds: 2 failureThreshold: 2Replace 8080 with the port your web server listens on inside the container. Keep timeoutSeconds
above the slowest indicator in the group.
Add a startup probe
Section titled “Add a startup probe”When the container needs time before it serves requests, for example to warm caches, add a startup probe. Kubernetes waits for it before it runs the liveness probe:
startupProbe: httpGet: path: /actuator/health/liveness port: 8080 periodSeconds: 2 failureThreshold: 30Choose what readiness checks
Section titled “Choose what readiness checks”By default, readiness checks maintenance mode and pending migrations. Add the dependencies without which an instance
cannot serve any request, and that can fail for one instance but not the others:
'groups' => [ 'liveness' => ['include' => ['ping']], 'readiness' => ['include' => ['readinessState', 'migrations', 'diskSpace']],],Keep liveness minimal. A liveness failure restarts the container, which does not fix a database
outage. Liveness and readiness explains the
trade-offs.
Take pods out of rotation with maintenance mode
Section titled “Take pods out of rotation with maintenance mode”While the application is in maintenance mode, readiness reports OUT_OF_SERVICE and liveness
stays UP. Kubernetes stops sending traffic but does not restart the pods.
By default, maintenance mode is a file in each pod, so php artisan down affects only the pod where
you run it:
kubectl exec deploy/my-app -- php artisan downTo take every pod out at once, store maintenance mode in a shared cache:
APP_MAINTENANCE_DRIVER=cacheAPP_MAINTENANCE_STORE=rediskubectl exec deploy/my-app -- php artisan downkubectl exec deploy/my-app -- php artisan upCheck the probes
Section titled “Check the probes”kubectl describe pod -l app=my-app | grep -A3 -E 'Liveness|Readiness'kubectl get endpoints my-appA pod that fails readiness disappears from the endpoints list. Its events show the failed probe and the HTTP status.