Use context: kubectl config use-context k8s-c1-H
Create a single Pod of image httpd:2.4.41-alpine
in Namespace default
. The Pod should be named pod1
and the container should be named pod1-container
. This Pod should only be scheduled on controlplane nodes. Do not add new labels to any nodes.
How to Schedule a Pod on Control Plane Nodes in Kubernetes
In Kubernetes, there are scenarios where you might want to schedule a Pod to run exclusively on control plane nodes. This guide will show you how to create a Pod that runs only on control plane nodes without adding any new labels to the nodes.
Step 1: Identify Control Plane Nodes and Their Taints
First, you need to identify the control plane node(s) in your cluster and check for any taints that might prevent Pods from being scheduled on them. Use the following commands:
1 2 3 4 5 6 7 8 9 |
kubectl get node # Find control plane node(s) kubectl describe node <controlplane-node-name> | grep Taint -A1 # Get control plane node taints kubectl get node <controlplane-node-name> --show-labels # Get control plane node labels |
Step 2: Create a Pod Template
Now that you have identified the control plane node, create a Pod template. Generate a basic Pod configuration with the following command:
1 2 3 4 5 |
kubectl run pod1 --image=httpd:2.4.41-alpine --dry-run=client -o yaml > pod1.yaml |
Step 3: Modify the Pod Configuration
Edit the pod1.yaml
file to ensure the Pod is only scheduled on control plane nodes. Open the file in a text editor and update it as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
apiVersion: v1 kind: Pod metadata: name: pod1 spec: containers: - name: pod1-container image: httpd:2.4.41-alpine tolerations: - key: "node-role.kubernetes.io/control-plane" effect: NoSchedule nodeSelector: node-role.kubernetes.io/control-plane: "" |
This configuration adds tolerations and a node selector to ensure the Pod is scheduled only on control plane nodes.
Step 4: Create the Pod
Once the configuration is set, create the Pod using the following command:
1 2 3 4 5 |
kubectl apply -f pod1.yaml |
Step 5: Verify the Pod Scheduling
Finally, verify that the Pod is running on the control plane node:
1 2 3 4 5 |
kubectl get pod pod1 -o wide |
You should see that the NODE
column indicates that the Pod is running on the specified control plane node.
By following these steps, you can ensure that your Pod is scheduled only on control plane nodes in your Kubernetes cluster. This method provides better control over where your workloads are running.