How Controllers create resources in a Kubernetes cluster?

316 views Asked by At

I am creating a K8s object creation workflow, and I want to be sure everything is correct. There is this nice flow in Heptio blogs, but controller manager is missing, which is where my doubts are.

If we read K8s docs, Controller Manager is always described as this loop that watches on the desired state of the cluster, and moves all the necessary strings to bring the current state into that (desired) state.

Fair enough, but we also know that kubelet has the container runtime, so kubelet creates containers or pods. We also know that kube-proxy makes the necessary changes in the iptable rules, so services will work properly. And so on. So how does exactly controller manager works?

To my knowledge, there are these processes (Informers/Watchers for each resource; not necessarily 1:1) that watch on resource changes through the API-Server, and add jobs to a Queue, that are consumed by the Worker node components. Would appreciate if anyone could correct me, if I'm wrong.

1

There are 1 answers

0
Rui On

I think you are right about how the controller manager works. To my best knowledge, controller manager in Kubernetes is a set of controllers such as node controller, pod controller and Deployment controller. Each controller list/watch specific resource and defines some callback functions like update, add and delete. When resource changes the controller call corresponding functions to bring the system to the desired state. You can even define your own CRD and corresponding controller to manage your resource, which is a very strong and flexible tool. The sample controller might be useful.