CKA · Question #37
CKA Question #37: Real Exam Question with Answer & Explanation
This question tests your ability to modify an existing Kubernetes Deployment to add a named container port, then expose it via a NodePort Service that references that named port.
Question
Reconfigure the existing deployment front-end and add a port specification named http exposing port 80/tcp of the existing container nginx. Create a new service named front-end-svc exposing the container port http. Configure the new service to also expose the individual Pods via a NodePort on the nodes on which they are scheduled.
Explanation
This question tests your ability to modify an existing Kubernetes Deployment to add a named container port, then expose it via a NodePort Service that references that named port.
Approach. First, patch the existing 'front-end' Deployment using 'kubectl edit deployment front-end' (or kubectl patch) to add a 'ports' entry under the nginx container spec: '- name: http, containerPort: 80, protocol: TCP'. Then create the NodePort Service with 'kubectl expose deployment front-end --name=front-end-svc --port=80 --target-port=http --type=NodePort', or write a YAML manifest with 'kind: Service', 'type: NodePort', and 'ports[].targetPort: http' referencing the named port. The NodePort field can be omitted to let Kubernetes auto-assign one (30000–32767 range), unless a specific port is required. Using the named port 'http' as targetPort (instead of numeric 80) is the key detail that ties the Service to the port declaration on the container.
Concept tested. Kubernetes Deployment port naming and NodePort Service creation - specifically: adding named containerPorts to a Deployment's pod spec, and wiring a Service's targetPort to a named port so that the Service correctly routes traffic to individual Pods and exposes them on every node via NodePort.
Reference. https://kubernetes.io/docs/concepts/services-networking/service/#nodeport
Topics
Community Discussion
No community discussion yet for this question.