Create a ReplicaSet that runs only 1 copy of our app at the moment.
Run this command, this will call you app endpoint every second.
while true ; do curl http://192.168.99.106:30000/test ; echo "\\n" ; sleep 1 ; done;
Instead of IP above, use your own IP.
Now scale up your app. Run 3 replicas.
You will start to get some failed request.
{"message":"Hello Fellas!!!","host.address":"172.17.0.5","app.version":"v1-web"}
curl: (7) Failed to connect to 192.168.99.106 port 30000: Connection refused
curl: (7) Failed to connect to 192.168.99.106 port 30000: Connection refused
curl: (7) Failed to connect to 192.168.99.106 port 30000: Connection refused
{"message":"Hello Fellas!!!","host.address":"172.17.0.5","app.version":"v1-web"}
{"message":"Hello Fellas!!!","host.address":"172.17.0.5","app.version":"v1-web"}
curl: (7) Failed to connect to 192.168.99.106 port 30000: Connection refused
curl: (7) Failed to connect to 192.168.99.106 port 30000: Connection refused
curl: (7) Failed to connect to 192.168.99.106 port 30000: Connection refused
{"message":"Hello Fellas!!!","host.address":"172.17.0.7","app.version":"v1-web"}
{"message":"Hello Fellas!!!","host.address":"172.17.0.7","app.version":"v1-web"}
{"message":"Hello Fellas!!!","host.address":"172.17.0.6","app.version":"v1-web"}
{"message":"Hello Fellas!!!","host.address":"172.17.0.6","app.version":"v1-web"}
{"message":"Hello Fellas!!!","host.address":"172.17.0.5","app.version":"v1-web"}
Why is this happening?
What happens right now is that, Service starts to send the traffic to a Pod as soon as Pod is started.
Kubernetes at the moment doesn't have any idea if our Pod is ready to accept connection.
Like liveness probe we have few options we can configure
initialDelaySeconds: Number of seconds after the container has started before liveness probes are initiated.
periodSeconds: How often (in seconds) to perform the probe. Default to 10 seconds. Minimum value is 1.
timeoutSeconds: Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1.
failureThreshold: When a Pod starts and the probe fails, Kubernetes will try failureThreshold times before giving up. Giving up in case of liveness probe means restarting the Pod. Defaults to 3. Minimum value is 1.
successThreshold: Minimum consecutive successes for the probe to be considered successful after having failed