title | description |
---|---|
GCP Google Kubernetes Engine Kubernetes Readiness Probes |
Implement GCP Google Kubernetes Engine Kubernetes Readiness Probes |
- Verify if GKE Cluster is created
- Verify if kubeconfig for kubectl is configured in your local terminal
# Configure kubeconfig for kubectl
gcloud container clusters get-credentials <CLUSTER-NAME> --region <REGION> --project <PROJECT>
# Replace Values CLUSTER-NAME, REGION, PROJECT
gcloud container clusters get-credentials standard-cluster-private-1 --region us-central1 --project kdaida123
# List Kubernetes Nodes
kubectl get nodes
- Implement
Readiness Probe
and Test it
- Sometimes, applications are temporarily unable to serve traffic.
- For example, an application might need to load large data or configuration files during startup, or depend on external services after startup.
- In such cases, you don't want to kill the application, but you don't want to send it requests either.
- Kubernetes provides readiness probes to detect and mitigate these situations.
- A pod with containers reporting that they are not ready does not receive traffic through Kubernetes Services.
- Readiness probes runs on the container during its whole lifecycle.
- Liveness probes do not wait for readiness probes to succeed.
- If you want to wait before executing a liveness probe you should use initialDelaySeconds or a startupProbe.
- Readiness and liveness probes can be used in parallel for the same container.
- Using both can ensure that traffic does not reach a container that is not ready for it, and that containers are restarted when they fail.
- File Name: 05-UserMgmtWebApp-Deployment.yaml
# Readiness Probe HTTP Request
readinessProbe:
httpGet:
path: /login
port: 8080
httpHeaders:
- name: Custom-Header
value: Awesome
initialDelaySeconds: 60
periodSeconds: 10
failureThreshold: 3 # Default Value
successThreshold: 1 # Default value
# Deploy Kubernetes Manifests
kubectl apply -f kube-manifests-readiness-probe
# List Pods
kubectl get pods
Observation:
1. You can see that Pod is running but it will not be ready for 60 seconds.
2. "initialDelaySeconds=60" is defined in readiness probe so it will mark
the pod as ready only after 60 seconds
3. Liveness probe will start working after "initialDelaySeconds: 120"
4. This way first Readiness probe will run later liveness probe will run.
# List Services
kubectl get svc
# Access Application
http://<LB-IP>
Username: admin101
Password: password101
# Delete Kubernetes Resources
kubectl delete -f kube-manifests-readiness-probe