Search code examples
kubernetesstartup

How does K8S auto-start the Deployments and DaemonSets?


I have installed K8S using Kubeadm and see the below pods across the control plane nodes and the worker nodes.

enter image description here

Kubelet is started as a systemd service, it looks at the /etc/kubernetes/manifests folder and starts the objects defined in the etcd.yaml, kube-apiserver.yaml, kube-controller-manager.yaml and kube-scheduler.yaml files. If I drop a yaml file in the same folder, kubelet observes the same and starts the appropriate K8S object.

I am not sure how the coredns Deployment, kube-proxy and the flannel DaemonSets shown in the above screenshot get automatically started once I start/reboot the control plane nodes and the worker nodes. Can someone help me with the K8S startup process for the same?


Solution

  • Kubeadm installs CoreDNS and kube-proxy in init addon phase. It's being installed after basic cluster functionality is already started (apiserver, controller manager etc.). Kubeadm installs it the same way you would run kubectl apply.

    Here is the code of kubeadm init addon phase if you want to see how it actually works under the hood.

    Apiserver, controller manager and scheduler have to be started using manifest folder (also known as static pods) because there is no other way (technically this is not 100% correct, because there are other methods, e.g. you can run your control plane using systemd). How do you start running stuff on kubernetes when there is no kubernetes yet? There is no api server to handle your requests, there is no scheduler to schedule your pods, there is no controller to manage resources. After the essential components are started, you can run pods in a regular way using api.

    Also, answering your question on what happens when you restart your control plane or nodes? You need to know that state of whole k8s cluster is hold in etcd. So when you reboot control plane, kubernetes reads state from etcd, compares it to reality and if there are differences, it adjusts reality to match the state in etcd. e.g. if there is no coredns running but there is coredns object in etcd, kubernetes is going to start it.