Question
Use Namespace project-tiger for the following.
Create a Deployment named deploy-important with label id=very-important (the pods should also have this label) and 3 replicas.
It should contain two containers, the first named container1 with image nginx:1.17.6-alpine and the second named container2 with image kubernetes/pause.
There should be only ever one Pod of that Deployment running on one worker node. We have two worker nodes: cluster1-worker1 and cluster1-worker2.
Because the Deployment has three replicas the result should be that on both nodes one Pod is running. THe third Pod won't be scheduled unless a new worker node will be added.
In a way we kind of simulate the behaviour of a DaemonSet here, but using a Deployment and a fixed number of replicas.
Answer
Generate manifest:
kubectl create deploy deploy-important --image=nginx:1.17.6-alpine --dry-run=client -o yaml
And adjust it:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
id: very-important
name: deploy-important
namespace: project-tiger
spec:
replicas: 3
selector:
matchLabels:
id: very-important
template:
metadata:
labels:
id: very-important
spec:
containers:
- image: nginx:1.17.6-alpine
name: container1
ports:
- containerPort: 80
hostPort: 8088
- image: kubernetes/pause
name: container2
You have to mention hostPort to container port. The kubernetes scheduler will be unable to schedule more than 1 pod on same host and in this way all nodes have at least one pod scheduled.kubectl apply -f dep.yaml
kubectl -n project-tiger get deploy
kubectl -n project-tiger get po