affintity and anti-affinity between pods. ensure webapp connect to local redis cache

9/3/2019

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.

  1. The redis deployment has PodAntiAffinity configured to ensure the scheduler does not co-locate replicas on a single node.
  2. The webapplication deployment has a pod affinity to ensure the app is scheduled with the pod that has label store (Redis).

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?

-- Geoffrey Samper
kubernetes
kubernetes-service

1 Answer

9/3/2019

This can be configured in the (redis) Service, but in general it is not recommended:

Setting spec.externalTrafficPolicy to the value Local will only proxy requests to local endpoints, never forwarding traffic to other nodes

This is a complex topic, read more here:

-- Janos Lenart
Source: StackOverflow