Kubernetes: Advanced Q&A

I’d like to share with you some questions we did to the Google Kubernetes team and that might be useful for others. Enjoy it

  1. Does each pod only have access to one node resources? (the node in which it lives?
    • Yes
  2. If I have two node pools, one with low memory and one with high memory, is Kubernetes smart to put the pods that use a lot of memory in the pool with high memory? Can it do it on-the-fly?
    • You can define requests and limits to ensure that pods are scheduled on nodes with sufficient resources. You can also utilize node affinity/anti-affinity to influence where pods go, or taint/toleration to block pools from accepting pods unless explicitly specified. More details on how Kubernetes handles resourcescan be found here.
  3. How do preemptive nodes in the cluster work? If I have two nodes in the cluster and each node has 4 pods, when one node is preempted, will Kubernetes move the 4 pods to another node? And when the other node is available again will the Kubernetes rebalance the location of the pods?
    • Preemptive nodes are created as a node pool. If your node pool is preempted and becomes unavailable, GKE will attempt to reschedule your pods in other available nodes (unless you set it up in your deployment spec to only deploy to preemptive nodes). When the node pool becomes available, GKE will schedule appropriate pods there (it will not rebalance automatically).
  4. How does in-memory disk cache work in the cluster? I’m referring to this cache. Each pod will have its cache or the cache is shared between all the pods in the node?
    • Pods have their own storage/cache isolated from each other when created, emptydir. By default, emptyDir volumes are stored on whatever medium is backing the node – that might be disk or SSD or network storage, depending on your environment. However, you can set the emptyDir.medium field to “Memory” to tell Kubernetes to mount a tmpfs (RAM-backed filesystem) for you instead. While tmpfs is very fast, be aware that
      unlike disks, tmpfs is cleared on node reboot and any files you write will count against your Container’s memory limit.
  5. We have an application that uses the name of the machine on which it is running to decide what it will do. The machine name must form a sequence from 0 to the total number of machines minus 1. Example: maq-0, maq-1, maq-2. Each application also needs to know the total number of machines. How to do this in kubernetes? I was able to do this using a statefulSet, but the total number of pods got hardcoded in the application. Any suggestion?
    • Assuming that we are looking at machines as pods, then StatefulSets are required. StatefulSets provide a stable network ID which allows for the naming convention specified. The current number of replicas can be acquired using the StatefulSetStatus v1 apps Kubernetes API.
  6. Is it possible to do a statefulSet without a headlessService? I am asking this because the application I want to run in the statefulSet does not need to be accessed by anyone (neither inside nor outside the cluster).
    • No, StatefulSets require a headlessService. You can use network policies to deny Ingress

Leave a Reply

Your email address will not be published. Required fields are marked *