concept topologyKey in category kubernetes

appears as: topologyKey, The topologyKey, topologyKey
Kubernetes in Action

This is an excerpt from Manning's book Kubernetes in Action.

The listing shows that this Deployment will create pods that have a hard requirement to be deployed on the same node (specified by the topologyKey field) as pods that have the app=backend label (see figure 16.4).

The cluster I’m using runs in three VMs on my local machine, so all the nodes are in the same availability zone, so to speak. But if the nodes were in different zones, all I’d need to do to run the frontend pods in the same zone as the backend pod would be to change the topologyKey property to failure-domain.beta.kubernetes.io/zone.

Understanding how topologyKey works

The way topologyKey works is simple. The three keys we’ve mentioned so far aren’t special. If you want, you can easily use your own topologyKey, such as rack, to have the pods scheduled to the same server rack. The only prerequisite is to add a rack label to your nodes. This scenario is shown in figure 16.5.

Figure 16.5. The topologyKey in podAffinity determines the scope of where the pod should be scheduled to.