Place One Pod per Node Without Using a DaemonSet
Scenario
You are working in the aws-ecr namespace on a Kubernetes cluster
with two worker nodes.
An application must be deployed with three replicas, but the design requires that no more than one Pod runs on the same worker node.
A DaemonSet must not be used to achieve this behavior.
Tasks
- Create a Deployment named
ecr-deploymentwith 3 replicas in theaws-ecrnamespace. - Apply the following labels to the Deployment and Pod template:
app: ecr-apptier: backend
- Configure the Deployment with two containers:
eks-container1using imagepublic.ecr.aws/docker/library/httpd:alpineeks-container2using imagepublic.ecr.aws/eks-distro/kubernetes/pause:3.10.1
- There should only ever be one Pod from that Deployment running on a single worker node. Use
topologyKey: kubernetes.io/hostnamefor this. - Verify the scheduling result:
- Two Pods should be in the
Runningstate - One Pod should remain in the
Pendingstate
- Two Pods should be in the
🧪 Test Cases
Level up your Server Side game — Join 20,000 engineers who receive insightful learning materials straight to their inbox