https://drive.google.com/file/d/1-3S5P8ol2oSQfaSaHRDfWMwdO58tk5TX/view?usp=sharing
apiVersion: v1
kind: Pod
metadata:
name: probeone
labels:
app: apache
spec:
containers:
- name: boxone
image: lovelearnlinux/webserver:v1
ports:
- containerPort: 80
readinessProbe:
tcpSocket:
port: 80 # โ Check if TCP port 80 is open
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
tcpSocket:
port: 80 # โ Same check, different purpose
initialDelaySeconds: 15
periodSeconds: 20
๐ Key Insight:
Both probes check the same TCP port, but they serve completely different purposes.
| Probe | Purpose | Effect When Fails | Use Case |
|---|---|---|---|
readinessProbe |
"Is the app ready to serve traffic?" | Removes Pod from Service endpoints (no restart) | Startup delay, maintenance mode |
livenessProbe |
"Is the app alive?" | Restarts the container | App deadlock, infinite loop, crash |
๐ฏ Your Configuration:
- Readiness: Starts after 5s, checks every 10s โ fast traffic control
- Liveness: Starts after 15s, checks every 20s โ slower auto-healing
๐ก Why tcpSocket?
- Simpler than
httpGetfor basic connectivity- Works for any TCP service (not just HTTP)
๐ก We need a Service to see readiness in action.
# 1. Save Pod YAML as pod-probes.yaml
kubectl apply -f pod-probes.yaml
# 2. Create Service
kubectl expose pod probeone --port=80 --target-port=80
# 3. Verify
kubectl get pods,svc
๐ก Block port 80 temporarily to simulate app not ready:
# On the Pod, block port 80 (simulate app startup)
kubectl exec probeone -- iptables -A INPUT -p tcp --dport 80 -j DROP
# Watch Endpoints (should become <none>)
kubectl get endpoints probeone -w
# NAME ENDPOINTS AGE
# probeone <none> 5s โ REMOVED FROM SERVICE!
# Test connectivity (should fail)
kubectl run debug --image=curlimages/curl -it --rm -- sh
# curl <http://probeone> โ Connection refused
# Unblock port 80
kubectl exec probeone -- iptables -D INPUT -p tcp --dport 80 -j DROP
# Watch Endpoints return
kubectl get endpoints probeone -w
# NAME ENDPOINTS AGE
# probeone 10.42.0.10:80 10s โ BACK IN SERVICE!
# Test connectivity (should work)
curl <http://probeone> # โ
Welcome page