CKA Exam Practice Series - 1
CKA Exam Practice Series
Q1 Create a single pod
Create a single Pod of image httpd:2.4.41-alpine in Namespace default. The Pod should be named pod1 and the container should be named pod1-container. This Pod should only be scheduled on a master node, do not add new labels any nodes.
Answer
To create a single Pod named pod1 with a container named pod1-container using the image httpd:2.4.41-alpine
that is scheduled only on a master node in the default namespace, first, it's easy to acreate a template by runnning dry-run
kubectl run pod1 --image=httpd:2.4.41-alpine --dry-run=client -o yaml > q1_tmpl.yaml
Then you can add the followings in the template yaml manifest:
vi q1_tmpl.yaml
apiVersion: v1 kind: Pod metadata: name: pod1 namespace: default spec: containers: - name: pod1-container # Change image: httpd:2.4.41-alpine tolerations: # Add - key: node-role.kubernetes.io/master # Add effect: NoSchedule # Add nodeSelector: # Add node-role.kubernetes.io/master: "" # Add
The tolerations field specifies a key and an effect. The key is set to node-role.kubernetes.io/master
, which matches the taint applied to master nodes, and the effect is set to NoSchedule
, which allows the Pod to be scheduled on the master node despite the taint.
In a Kubernetes cluster, a toleration is used to allow a Pod to be scheduled on a node that has a taint. A taint is a label on a node that repels Pods that do not tolerate it. By default, the master node in a Kubernetes cluster has a taint applied to it with the key node-role.kubernetes.io/master
and the effect NoSchedule
. This taint is applied to prevent regular Pods from being scheduled on the master node, which is reserved for system-level tasks.
In order to schedule a Pod on the master node, you need to add a toleration to the Pod's spec that matches the key and effect of the taint applied to the master node. The tolerations field in a Pod's spec is an array of tolerations, each of which specifies a key and an effect.
To find the tolerations for a Pod, you can use the kubectl describe pod command. For example, to get the tolerations for a Pod named my-pod, you can run:
kubectl describe pod my-pod
This command will display detailed information about the Pod, including the tolerations that have been added to it.
To find the tolerations for a node, you can use the kubectl describe node command. For example, to get the tolerations for a node named my-node, you can run:
kubectl describe node my-node
This command will display detailed information about the node, including the taints that have been applied to it and the tolerations that have been added to it.
It's worth noting that while you can schedule regular Pods on a master node using tolerations, it is generally not recommended to do so, as it can interfere with the proper functioning of the Kubernetes control plane that runs on the master node.
To complete this question however, creating a pod on the master node, you can run;
kubectl apply -f q1_tmpl.yaml
This command will create the Pod with the specified name, container, image, toleration, and nodeSelector in the default namespace.