Kubernetes - Readiness And Liveness Probes πΈ
Description π
At times you may want to check if a container
is ready to serve requests. Or you may want to check if a container
is alive and healthy. Thatβs where readinessProbes
and livenessProbes
come in.
-
Readiness Probes
readinessProbes
are used to check if acontainer
is ready to serve requests. If areadinessProbe
fails, thecontainer
will not receive any traffic from aservice
. However, if areadinessProbe
fails, thecontainer
will not be restarted, unless it is alsounhealthy
. -
Liveness Probes
livenessProbes
are used to check if acontainer
is alive and healthy. If alivenessProbe
fails, thecontainer
will be restarted.livenessProbes
are useful whencontainers
become unresponsive due to memory leaks or deadlocks.
Examples π§©
-
sample
readinessProbe
definitionapiVersion: v1 kind: Pod metadata: name: readiness-probe spec: containers: - name: readiness-probe image: nginx readinessProbe: httpGet: path: /index.html port: 80 # for tcp # tcpSocket: # port: 80 # for exec # exec: # command: # - cat # - /tmp/healthy initialDelaySeconds: 5 periodSeconds: 5
-
sample
livenessProbe
definitionapiVersion: v1 kind: Pod metadata: name: readiness-probe spec: containers: - name: web-app image: web-app ports: - containerPort: 8080 livenessProbe: httpGet: path: /health port: 8080 # for tcp # tcpSocket: # port: 8080 # for exec # exec: # command: # - cat # - /tmp/healthy initialDelaySeconds: 5 periodSeconds: 5
-
sample
pod
withreadiness
andliveness
probeapiVersion: v1 kind: Pod metadata: labels: name: simple-webapp name: simple-webapp spec: containers: - name: simple-webapp image: kodekloud/webapp-delayed-start imagePullPolicy: Always env: - name: APP_START_DELAY value: "80" ports: - containerPort: 8080 protocol: TCP readinessProbe: httpGet: path: /ready port: 8080 livenessProbe: httpGet: path: /live port: 8080 initialDelaySeconds: 80 periodSeconds: 1