Assigning a Kubernetes Pod to a Specific Node
Introduction
Kubernetes scheduling usually doesn’t need much help in order to determine which node to run a pod on. However, you may occasionally wish to have a little more control. In this lab, you will be able to practice the process of ensuring a pod runs on a specific node.
Solution
Log in to the lab server using the credentials provided:
ssh cloud_user@<PUBLIC_IP_ADDRESS>
Configure the auth-gateway Pod to Only Run on k8s-worker2
Attach a label to
k8s-worker2.kubectl label nodes k8s-worker2 external-auth-services=trueOpen
auth-gateway.yml:vi auth-gateway.ymlAdd a
nodeSelectorto theauth-gatewaypod descriptor:... spec: nodeSelector: external-auth-services: "true" ...Save and exit the file by pressing Escape followed by
:wq.Delete and re-create the pod:
kubectl delete pod auth-gateway -n beebox-authkubectl create -f auth-gateway.ymlVerify the pod is scheduled on the
k8s-worker2node:kubectl get pod auth-gateway -n beebox-auth -o wide
Configure the auth-data Deployment’s Replica Pods to Only Run on k8s-worker2
Open
auth-data.yml:vi auth-data.ymlAdd a nodeSelector to the pod template in the deployment spec (it will be the second
specin the file):... spec: ... template: ... spec: nodeSelector: external-auth-services: "true" ...Save and exit the file by pressing Escape followed by
:wq.Update the deployment:
kubectl apply -f auth-data.ymlVerify the deployment’s replicas are all running on
k8s-worker2:kubectl get pods -n beebox-auth -o wide