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
readinessProbesare used to check if acontaineris ready to serve requests. If areadinessProbefails, thecontainerwill not receive any traffic from aservice. However, if areadinessProbefails, thecontainerwill not be restarted, unless it is alsounhealthy. -
Liveness Probes
livenessProbesare used to check if acontaineris alive and healthy. If alivenessProbefails, thecontainerwill be restarted.livenessProbesare useful whencontainersbecome unresponsive due to memory leaks or deadlocks.
Examples π§©
-
sample
readinessProbedefinitionapiVersion: 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
livenessProbedefinitionapiVersion: 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
podwithreadinessandlivenessprobeapiVersion: 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