Probes in Kubernetes
Probes in Kubernetes
Kubernetes probes are essential for maintaining the health and availability of your
applications. They periodically check the status of your containers and take action based on
the results. Let's dive into the different types of probes and how they can be optimized:
1. Liveness Probe:
2. Readiness Probe:
3. Startup Probe:
1. Probe Configuration:
initialDelaySeconds : Configure the initial delay before the first probe starts.
Allows your application time to initialize.
periodSeconds : Define the interval between consecutive probes.
timeoutSeconds : Specify the timeout for each probe.
successThreshold : Determine the number of consecutive successful probes
required after a failure to consider the container healthy again.
failureThreshold : Set the number of consecutive failed probes that trigger a
restart (liveness, startup) or removal from service endpoints (readiness).
2. Resource Efficiency:
Avoid resource-intensive probes: Ensure your probes are lightweight and don't
consume excessive resources, especially when running frequently.
Consider probe frequency: Balance the need for frequent health checks with
resource consumption. Adjust the periodSeconds accordingly.
3. Probe Logic:
Tailor probes to your application's specific needs: Understand the critical
components and dependencies of your application and design probes that
accurately reflect its health.
Handle probe failures gracefully: Implement appropriate error handling and
logging within your application to diagnose and address probe failures effectively.
Example:
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- name: my-app
image: my-image
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 15
periodSeconds: 5
startupProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 5
failureThreshold: 30