Startup Probe in Kubernetes: What It Is and How It Works
startupProbe in Kubernetes is a special check that tells the system when an application inside a container has started successfully. It helps Kubernetes wait longer for slow-starting apps before marking them as failed, avoiding premature restarts.How It Works
Imagine you have a slow cooker that takes a long time to prepare a meal. You wouldn’t want to open the lid too soon and think the meal is not ready. Similarly, some applications inside Kubernetes containers take longer to start up. The startupProbe acts like a timer and a check to see if the app has started properly.
When a container starts, Kubernetes uses the startupProbe to check if the app is ready. If the app takes a long time, Kubernetes keeps checking without restarting the container too early. Once the app passes the startup check, Kubernetes switches to using other probes like livenessProbe to monitor if the app stays healthy.
Example
This example shows a startupProbe that checks if a web server is ready by trying to connect to port 8080. It waits 5 seconds before starting checks and tries every 3 seconds, failing after 10 tries.
apiVersion: v1
kind: Pod
metadata:
name: startup-probe-example
spec:
containers:
- name: slow-start-app
image: nginx
startupProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 5
periodSeconds: 3
failureThreshold: 10
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
When to Use
Use startupProbe when your application takes a long time to start and might fail liveness checks before it is ready. This prevents Kubernetes from restarting the container too soon.
For example, apps that load large data, run migrations, or initialize complex services benefit from startup probes. It improves stability by giving the app enough time to become healthy.
Key Points
- Startup probe checks if the app has started successfully.
- It delays liveness checks until startup is complete.
- Prevents premature container restarts.
- Useful for slow-starting applications.
- Configured with
initialDelaySeconds,periodSeconds, andfailureThreshold.