In the documentation about affinity and anti-affinity rules for kubernetes there is a pratical use case arround a web application and a local redis cache.
To connect to the redis from the webapp we would have to define a service.
Question: How are we sure that the webapp will always use the redis that is co-located on the same node and not another one? If I read the version compatibility from Kubernetes v1.2 the iptables mode for kube-proxy became the default.
Reading the docs about iptable mode for kube-proxy it says by default, kube-proxy in iptables mode chooses a backend at random.
So my answer to the question would be: No we can't be sure. If you want to be sure then put the redis and webapp in one pod?
This can be configured in the (redis) Service, but in general it is not recommended:
Setting
spec.externalTrafficPolicy
to the valueLocal
will only proxy requests to local endpoints, never forwarding traffic to other nodes
This is a complex topic, read more here: