Knative uses more frequent probing than standard Kubernetes to reduce Pod cold start latency. Configure liveness probes and readiness probes in a Knative Service to keep your application healthy and ready to receive traffic.
How it works
Knative handles liveness and readiness probes differently from standard Kubernetes:
-
Liveness probe: Monitors whether a container is alive. If a container enters the Failed state or its process crashes, the kubelet restarts the container.
-
Readiness probe: Manages traffic routing during auto scaling. Only Pods in the Ready state receive traffic, which keeps the service stable and responsive.
The following diagram shows how probes work in Knative.
-
Define
readinessProbeorlivenessProbefields in a Knative Service Custom Resource (CR). -
The kubelet sends liveness probes directly to the specified containers.
-
Knative rewrites the readiness probes and forwards them to the
queue-proxycontainer. Probing starts from the Activator component or thequeue-proxycontainer to verify that the entire network link is configured and ready.When no probes are defined, Knative automatically creates default readiness probes for the primary container. These default probes check TCP sockets on the ports of Knative Services.
-
The
queue-proxycontainer aggregates readiness probe results from all containers, including the primary container and sidecar containers. Whenqueue-proxyreturns successful responses and the Knative network layer is configured, Knative marks the Pod as ready to accept traffic.
Prerequisites
Before you begin, ensure that you have:
-
Knative deployed in your ACS cluster. For more information, see Deploy Knative
Configure probes
Add the readinessProbe or livenessProbe field to a Knative Service to configure readiness probes and liveness probes. The configuration follows the same format as standard Kubernetes. For more information, see Configure liveness, readiness and startup probes.
The following example configures both probe types for two containers. The readiness probe port can differ from containerPort.
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: 8089
Supported probe types
| Probe type | Description |
|---|---|
httpGet |
Sends an HTTP GET request to the container. The probe succeeds based on the returned status code. |
tcpSocket |
Attempts to open a TCP connection to the container. The probe succeeds if the connection is established. |
exec |
Runs a command inside the container. The probe succeeds based on the exit code of the command. |
grpc |
Calls a method defined by the gRPC Health Checking Protocol to check the health status and liveness of services. |
Limitations
-
Custom
PreStophooks are not supported. Knative provides a built-in PreStop hook to handle graceful shutdown.