Question
Do the following in namespace default.
Create a single pod named ready-if-service-ready of image nginx:1.16.1-alpine.
Configure LivenessProbe which simply runs true.
Also, configure a ReadinessProbe which does check if the url http://service-am-i-ready:80 is reachable, you can use wget -T2 -O- http://service-am-i-ready:80 for this.
Start the pod and confirm it isn't ready because of ReadinessProbe.
Create a second pod named am-i-ready of image nginx:1.16.1-alpine with label id: cross-server-ready.
The already existing Service service-am-i-ready should now have the second pod as endpoint.
Now, the first pod should be in ready state, confirm that.
Answer
Generate manifest for the first pod:
kubectl run ready-if-service-ready --image=nginx:1.16.1-alpine --dry-run=client -o yaml
Adjust it:
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: ready-if-service-ready
name: ready-if-service-ready
spec:
containers:
- image: nginx:1.16.1-alpine
name: ready-if-service-ready
livenessProbe:
exec:
command: ["true"]
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
exec:
command: ["wget -T2 -O- http://service-am-i-ready:80"]
initialDelaySeconds: 5
periodSeconds: 10
Apply the manifest to the cluster:
kubectl appply -f pod1.yaml
Get the status:
kubectl get po ready-if-service-ready -w
Can be noticed that the pod is not in the ready state yet.kubectl run am-i-ready --image=nginx:1.16.1-alpine --labels=id=cross-server-ready
Get second pod IP and check if it is matching service endpoint:
kubectl get po am-i-ready -o wide
kubectl describe svc service-am-i-ready
It should have the IP as endpoint. Now, check the first pod status:
kubectl get po ready-if-service-ready
it should be in the ready state.