Static Pods
- The
kubeletfunctions as one of the many Control Plane components in Kubernetes. - The
kubeletrelies on thekubeapiserver for which instructions to run on the node.- The decision was made by the
kubeScheduler, which is then stored in theetc data store.
- The decision was made by the
- What if you removed the ControlPlane node entirely from the cluster and only has the Worker Node and its
kubelet.- The
kubeletor “captain” of the node can manage the node independently. - On the Worker Node we have the
kubeletandDockerto run the containers. - A
kubeapiserver does not exist.
- The
- The one action the
kubeletknows to do is to create pods.- The one problem is there is no
kubeapiserver available to provide pod details. - How do you provide a pod definition file to the
kubeletwithout akubeapiserver?- You can configure the
kubeletto read the pod definition file from a set location (/etc/kubernetes/manifestsinstead).- Place the pod definition files there.
- The
kubeletperiodically checks this directory and reads the files there. - It creates the pod and ensures that it stays alive (if the application crashes, the pod is also restarted).
- If any of the pod definition files are changed in the directory, the
kubeletrecreates the pods. - If a file is removed from the directory, the pod is deleted automatically.
- This setup is now known as a Static Pod. You cannot create Replicasets, Deployments or anything similar. Only Pods.
- You can configure the
- The one problem is there is no
- The
kubeletonly works at a Pod level. - The directory can be created anywhere on the host.
- It is a passed in as an object whilst the
kubeletis running the service.
- It is a passed in as an object whilst the
- Under
kubelet.service, the option to specify the directory where the pod manifest files are is:--pod-manifest-path=/etc/Kubernetes/manifest - The above line is under
ExecStart=/usr/local/bin/kubelet - Another way aside from mentioning the option specifically in the
kubelet.servicefile, is by creating a separateyamlfile and then linking to thatyamlfile in thekubelet.servicefile:ExecStart=/usr/local/bin/kubelet --config=kubeconfig.yaml - Then in
kubeconfig.yamlyou have to set thestaticPodPathlike so:staticPodPath: /etc/kubernetes/manifest - When the Static Pods are created, you can view them via the
docker pscommand.- For
cri-o, we usecrictl ps. - For
containerd, you can usenerdctl ps- We are not able to use
kubectlhere, as we do not have thekube api serveravailable.
- We are not able to use
- For
- The
kubeletworks by taking in requests from different inputs.- These can be from the pod definition files from the Static Pods directory as mentioned above.
- The second way is from an HTTP API endpoint - that is how the
kube-apiserverprovides input to thekubelet.
kubeletcan createStatic Podsand those from thekube-apiserverat the same time.- The
kube-apiserveris also aware of the pods being created by thekubelet.
- The
kubectl get podswill show theStatic Podsas well.- If the Worker Node’s
kubeletis part of the cluster, it creates a mirror object in thekube-apiserver. Thekube-apiserveronly has a read-only mirror of the pod.- Can receive details of the pods from the
kube-apiserver, but you cannot edit or delete them.- The pods can only be deleted from the Worker Node’s manifest directory.
- The name of the pod is automatically appended with the node name
static-web-node01.
- Can receive details of the pods from the
- If the Worker Node’s
- Useful uses of
Static Podsto deploy ControlPlane components as Pods on a node.- Install a
kubeletservice on all of the Master Nodes. - Create pod definition files that use Docker images of the various Control Plane components –>
kube-apiserver,etcd,controller-managerand so on. - Then place the manifest files in the directory of each Worker Node.
- Install a
- It makes it easier not to need to download and setup additional applications.
- The above method is how the
kubeadmtool sets up a Kubernetes cluster.- That is why when you list the pods in the
kube-systemnamespace withkubectl get pods -n kube-system, you see each component as a pod.
- That is why when you list the pods in the
- The above method is how the
- Difference between static pods and DaemonSets –>
- Static Pods:
- Created by
kubelet. - Deploys Control Plane components as Static Pods.
- Created by
- DaemonSets:
- Created by the
kube-apiserver. - Deploys Monitoring Agents, Logging Agents on Nodes.
- Created by the
- Static Pods:
- Both Static Pods and DaemonSets are ignored by the
kube-scheduler.