Kubernetes Advanced Guide π
Pod Management with kubectl π οΈ
Replace a Pod
To delete and recreate a pod using a configuration file:Get Pods Information
Watch the status of all pods:kube-system namespace:
Scheduling Pods in Specific Nodes ποΈ
Schedule a Pod on a Specific Node
Use the node name extension to schedule a pod. If the pods are not scheduling, ensure that the scheduler is available to auto-schedule the pod:kube-system pods or the scheduler.
Labels & Selectors π
Filtration with Labels & Selectors
Get pods with a specific label:Filtering with Metadata Labels
In the below example, metadata labels are used only to filter the replica-set/deployments created. However, if you put the labels in thespec.template section, you will be able to filter the pods of those labels in your cluster. The selector section connects the replica set to the container in the spec section.
Annotations π
Annotations are used to store information that might be usable in some cases, such as phone numbers, email IDs, build numbers, etc.Taints and Tolerations π«
Taints (Node Level)
There are three types of taints:- NoSchedule: Do not schedule new pods to the node, but existing pods will remain.
- PreferNoSchedule: Prefer not to schedule pods, but itβs not guaranteed.
- NoExecute: Do not schedule new pods to this tainted node, and existing pods will be evicted if they do not tolerate the taint.
Tolerations (Pod Level)
Values of tolerations must be in quotes:Notes on Taints and Tolerations
Taints and tolerations do not guarantee that a pod will only schedule to the tainted node. They protect against unwanted pods scheduling to that node. For guaranteed scheduling, use NodeAffinity.Removing a Taint
To remove a taint from a node:Node Selector & Label Nodes
Label nodes according to their capacity. For example, label a node asLarge:
nodeSelector to schedule pods on the labeled node.
Node Affinity
Node affinity rules:- requiredDuringScheduling: Only schedule the pod if the match expression is met.
- preferDuringScheduling: Prefer scheduling the pod according to the match expression.
- ignoreDuringExecution: Do nothing if node labels change in the future.
- RequiredDuringExecution: Evict or terminate pods if node labels change in the future.
Combining Taints and Node Affinity
To ensure that a pod schedules only to the desired node, use a combination of taints and node affinity.Pod Resources π
YAML for Pod Resources & Limits
Pods cannot exceed their CPU limit as defined in the YAML file. However, they can exceed their memory limit, resulting in termination with anOOM (Out of Memory) error.
Namespace Level Resource Quota
Limit the resources for all pods in a namespace.Editing Pods and Deployments βοΈ
Editing a Pod
You cannot edit certain specifications of an existing pod. Editable fields include:spec.containers[*].imagespec.initContainers[*].imagespec.activeDeadlineSecondsspec.tolerations
Editing Deployments
With deployments, you can easily edit any field/property of the pod template. The deployment will automatically delete and create a new pod with the updated changes:DaemonSets π
DaemonSets ensure that a pod runs on each node in the cluster. They are useful for monitoring and logging solutions, such as deployingfluentd in all pods for log collection.
Get information about DaemonSets:
Static Pods π‘οΈ
Static pods run standalone on any node in the cluster. Place the pod YAML file in/etc/kubernetes/manifests, and the kubelet will detect and manage the pod. Static pods are managed by the kubelet of the node and not the API server.
To find static pods, look for pods with node names at the end or check the ownership section in the podβs YAML.
Multiple Schedulers π
Learn more about Kubernetes scheduling:- Scheduling Code Hierarchy Overview
- Advanced Scheduling in Kubernetes
- How Does the Kubernetes Scheduler Work?
