Knative uses more frequent and active probing than standard Kubernetes to reduce pod cold start time and accelerate the transition from startup to running state. Add liveness probes and readiness probes to a Knative Service to keep your application healthy and traffic-ready.
How it works
Liveness probes monitor container health. If a container enters the Failed state or its service fails to start, the liveness probe restarts the container.
Readiness probes manage auto scaling by ensuring only pods in the Ready state receive traffic, improving service stability and response speed.
Probes in Knative follow a four-step sequence:
Define readiness probes or liveness probes in a Knative Service CustomResource (CR).
The kubelet sends liveness probes to the specified containers.
Knative rewrites readiness probes and sends them to the queue-proxy container. Probing starts from the Activator component or the queue-proxy container to verify that the entire network link is configured and ready.
Knative defines readiness probes for the queue-proxy container. The queue-proxy aggregates readiness probe results from all containers — the primary container and any sidecar containers. When queue-proxy returns successful responses and the Knative network layer is configured, Knative considers the pods healthy and ready to accept traffic.
When no probes are defined, Knative creates default readiness probes for the primary container. These probes check the TCP sockets on the ports of Knative Services.
Prerequisites
Before you begin, ensure that you have:
Knative deployed in your cluster. For more information, see Deploy Knative.
Configure probes
Add the readinessProbe or livenessProbe field to a Knative Service. The configuration follows the same format as standard Kubernetes probes. For the full parameter reference, see Configure liveness, readiness and startup probes.
The following example configures two containers, each with an HTTP GET readiness probe and a TCP socket liveness probe:
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: runtime
namespace: default
spec:
template:
spec:
containers:
- name: first-container
image: <YOUR-IMAGE> # Replace with the actual image name.
ports:
- containerPort: 8080
readinessProbe: # Checks when the container is ready to receive traffic.
httpGet:
port: 8080 # Can differ from containerPort.
path: "/health"
livenessProbe: # Checks whether the container is alive.
tcpSocket:
port: 8080
- name: second-container
image: <YOUR-IMAGE> # Replace with the actual image name.
readinessProbe:
httpGet:
port: 8089
path: "/health"
livenessProbe:
tcpSocket:
port: 8089Supported probe types
| Probe type | Description |
|---|---|
httpGet | Sends an HTTP GET request and checks the returned status code. |
tcpSocket | Attempts to open a TCP connection to the specified port. |
exec | Runs a command in the container and checks the exit code. |
grpc | Calls a method defined by the gRPC Health Checking Protocol. |
Limitations
Custom PreStop probes are not supported. Knative provides a built-in PreStop hook to handle graceful shutdown.