0
0
Kubernetesdevops~5 mins

Startup probe concept in Kubernetes - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes an application takes a long time to start. Kubernetes needs a way to know when the app is ready to start checking if it is healthy. The startup probe helps Kubernetes wait until the app is fully started before running other health checks.
When your app takes a long time to initialize before it can serve requests.
When you want to avoid Kubernetes killing your app too early because it thinks the app is not ready.
When you have complex startup tasks like loading large data or connecting to external services.
When you want to separate startup health checks from regular readiness or liveness checks.
When you want to improve stability by letting Kubernetes know exactly when your app is ready.
Config File - startup-probe.yaml
startup-probe.yaml
apiVersion: v1
kind: Pod
metadata:
  name: startup-probe-example
spec:
  containers:
  - name: my-app
    image: nginx:1.23
    startupProbe:
      httpGet:
        path: /healthz
        port: 80
      failureThreshold: 30
      periodSeconds: 10
    readinessProbe:
      httpGet:
        path: /healthz
        port: 80
      periodSeconds: 5
    livenessProbe:
      httpGet:
        path: /healthz
        port: 80
      initialDelaySeconds: 15
      periodSeconds: 20

This YAML defines a Pod with one container running nginx.

The startupProbe checks the /healthz path on port 80 every 10 seconds and allows up to 30 failures before marking the container as failed. This lets Kubernetes wait longer during startup.

The readinessProbe checks if the app is ready to receive traffic every 5 seconds.

The livenessProbe checks if the app is alive every 20 seconds, starting 15 seconds after the container starts.

Commands
This command creates the Pod with the startup probe configuration so Kubernetes can manage the container's startup health.
Terminal
kubectl apply -f startup-probe.yaml
Expected OutputExpected
pod/startup-probe-example created
This command checks the status of the Pod to see if it is running and ready after applying the startup probe.
Terminal
kubectl get pods startup-probe-example
Expected OutputExpected
NAME READY STATUS RESTARTS AGE startup-probe-example 1/1 Running 0 10s
This command shows detailed information about the Pod, including the results of the startup probe and other health checks.
Terminal
kubectl describe pod startup-probe-example
Expected OutputExpected
Name: startup-probe-example Namespace: default Status: Running Containers: my-app: Container ID: docker://abcdef123456 Image: nginx:1.23 State: Running Ready: True Restart Count: 0 Startup Probe: http-get http://:80/healthz delay=0s timeout=1s period=10s #success=1 #failure=30 Readiness Probe: http-get http://:80/healthz delay=0s timeout=1s period=5s Liveness Probe: http-get http://:80/healthz delay=15s timeout=1s period=20s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 1m default-scheduler Successfully assigned default/startup-probe-example to node-1
Key Concept

If you remember nothing else from this pattern, remember: the startup probe tells Kubernetes when your app has fully started before running readiness or liveness checks.

Common Mistakes
Not setting a startup probe for apps that take a long time to start.
Kubernetes may kill the app early thinking it failed to start, causing restarts and downtime.
Add a startup probe with appropriate failureThreshold and periodSeconds to allow enough startup time.
Using the same probe settings for startup, readiness, and liveness probes.
Startup probe needs different timing because it only runs during startup, while readiness and liveness run continuously.
Configure startup probe separately with longer timeouts and failure thresholds.
Summary
Create a Pod with a startup probe to let Kubernetes know when the app is fully started.
Use kubectl apply to create the Pod and kubectl get pods to check its status.
Use kubectl describe pod to see detailed probe results and events.