https://drive.google.com/file/d/1-3S5P8ol2oSQfaSaHRDfWMwdO58tk5TX/view?usp=sharing

๐Ÿ” YAML Breakdown

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.


๐Ÿ“Œ Readiness vs Liveness: The Critical Difference

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:

๐Ÿ’ก Why tcpSocket?


๐Ÿงช k3s Lab: Observe Both Probes in Action

๐Ÿ”ง Step 1: Deploy Pod + Service

๐Ÿ’ก 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

๐Ÿ”ง Step 2: Test Readiness (Simulate Startup Delay)

๐Ÿ’ก 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

๐Ÿ”ง Step 3: Restore Readiness

# 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

๐Ÿ”ง Step 4: Test Liveness (Simulate App Crash)