Question : The Nautilus DevOps team is doing some testing around the Kubernetes cluster for pods, deployments etc. A new ticket has been raised by one of the developer with some particular requirements. Find below more details and perform the task accordingly.
Create a label for node node01 color=grey,
Based on the new label created for node01 using nodeAffinity matchExpressions create a new deployment named grey, use image nginx with latest tag only and remember to mention tag i.e nginx:latest and 3 replicas; ensure container name is nginx-container and that it gets placed on the node01 node only. Also make sure all pods are in running state before clicking on FINISH.
Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.
1. At first kubectl utility configure and working from jump server, run below commands
thor@jump_host
/$ kubectl get deploy No resources
found in default namespace. thor@jump_host
/$ thor@jump_host
/$ kubectl get nodes --show-labels NAME STATUS ROLES
AGE VERSION LABELS controlplane Ready
master 3m47s v1.19.0
beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=controlplane,kubernetes.io/os=linux,node-role.kubernetes.io/master= node01 Ready <none> 3m10s
v1.19.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux thor@jump_host
/$ |
thor@jump_host
/$ kubectl label nodes node01 color=grey node/node01
labeled thor@jump_host
/$ |
( Refer Below Video for more clarity )
thor@jump_host
/$ vi /tmp/affinity.yml thor@jump_host
/$ cat /tmp/affinity.yml apiVersion:
apps/v1 kind: Deployment metadata: name: grey spec: replicas: 3 selector: matchLabels: app: nginx-pod template: metadata: labels: app: nginx-pod spec: affinity: nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: color operator: In values: - grey containers: - name: nginx-container image: nginx:latest thor@jump_host
/$ |
thor@jump_host
/$ kubectl create -f /tmp/affinity.yml deployment.apps/grey
created thor@jump_host /$ |
thor@jump_host
/$ kubectl get deploy NAME READY
UP-TO-DATE AVAILABLE AGE grey 3/3
3 3 10s thor@jump_host
/$ thor@jump_host
/$ kubectl get pods -o wide NAME READY STATUS
RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES grey-5c4bc995f6-bnf4m 1/1
Running 0 62s 10.244.1.4 node01
<none>
<none> grey-5c4bc995f6-gh22l 1/1
Running 0 62s 10.244.1.2 node01
<none>
<none> grey-5c4bc995f6-x29xw 1/1
Running 0 62s 10.244.1.3 node01
<none>
<none> thor@jump_host
/$ |
6. Click on Finish & Confirm to complete the task successful
Happy Learning!!!!
Apart from this if you need more clarity, I have made a tutorial video on this , please go through and share your comments. Like and share the knowledge
0 Comments