Step 1: Identify the Labels on node01
Begin by examining the labels on node01. Run the following command to obtain detailed node information:beta.kubernetes.io/arch with the value amd64.
──────────────────────────────
Step 2: Apply a New Label on node01
Next, assign a new labelcolor=blue to node01. Execute the following command:
Labeling nodes strategically can help in managing pod placement and workload isolation across your Kubernetes cluster.
Step 3: Create the “blue” Deployment with Node Affinity for node01
Create a deployment named blue utilizing the nginx image with three replicas:color=blue. Integrate the following YAML snippet under the spec.template.spec section:
Step 4: Create the “red” Deployment with Node Affinity for the Control Plane
In the next step, we create a deployment named red using the nginx image with two replicas. The deployment is configured to run its pods exclusively on the control plane node by leveraging thenode-role.kubernetes.io/master label.
First, generate the deployment YAML file using a dry run:
red.yaml file to add the node affinity rule under the spec.template.spec section. Update the file to resemble the following:
Using a dry run to generate deployment YAML files allows you to safely modify pod specifications—such as adding node affinity—before applying the changes to your cluster.
Additional Diagram Reference
The image below illustrates the process for creating the red deployment with the nginx image, two replicas, and node affinity targeting the control plane node by checking for the labelnode-role.kubernetes.io/master:

Conclusion
In this lesson, you learned how to:- Identify node labels with the
kubectl describe nodecommand. - Apply custom labels to nodes using the
kubectl labelcommand. - Configure node affinity in a deployment to restrict pod scheduling based on node labels.
- Generate and modify deployment YAML files using a dry run to enforce node affinity settings for both worker nodes and control plane nodes.