CKAD Services and Networking 3 — Questions and Answers
Question 1: What is the valid port range for NodePort Services in Kubernetes?
- 1024-65535
- 8000-9000
- 30000-32767 (Correct answer)
- 0-65535
Correct answer: 30000-32767
By default, Kubernetes allocates NodePort values in the range 30000-32767 to avoid conflicts with well-known ports.
Question 2: How do you expose a Deployment named 'webapp' on port 80, targeting container port 8080, as a ClusterIP service?
- kubectl expose deployment webapp --port=80 --target-port=8080 (Correct answer)
- kubectl create service clusterip webapp --port=80 --container-port=8080
- kubectl expose deployment webapp --service-port=80 --pod-port=8080
- kubectl apply service webapp --port=80 --target=8080
Correct answer: kubectl expose deployment webapp --port=80 --target-port=8080
'kubectl expose deployment' creates a Service; '--port' is the service port and '--target-port' is the container port.
Question 3: What does 'sessionAffinity: ClientIP' in a Service spec do?
- Routes all requests to the pod with the lowest IP
- Ensures all requests from the same client IP go to the same pod (Correct answer)
- Blocks requests from specific IP ranges
- Rounds-robin traffic based on source IP hash
Correct answer: Ensures all requests from the same client IP go to the same pod
ClientIP session affinity makes the service route all requests from the same client IP to the same backend pod.
Question 4: Which kubectl command shows the endpoints (pod IPs) backing a Service named 'myservice'?
- kubectl get service myservice --endpoints
- kubectl get endpoints myservice
- kubectl describe endpoints myservice
- Both B and C show endpoint IPs (Correct answer)
Correct answer: Both B and C show endpoint IPs
Both 'kubectl get endpoints myservice' and 'kubectl describe endpoints myservice' show the pod IPs backing the service.
Question 5: An Ingress uses 'pathType: Prefix'. What does this mean for path matching?
- Only exact path matches are routed
- Any URL starting with the specified path prefix is routed to the backend (Correct answer)
- Regex patterns are supported
- The path is case-insensitive
Correct answer: Any URL starting with the specified path prefix is routed to the backend
'pathType: Prefix' routes requests where the URL path begins with the specified prefix, including the exact path and any sub-paths.
Question 6: What happens to a pod's DNS resolution when it uses 'dnsPolicy: ClusterFirst'?
- All DNS queries go to the node's DNS first
- DNS queries are first checked against the cluster DNS (CoreDNS), with non-cluster queries forwarded upstream (Correct answer)
- DNS is disabled for the pod
- All queries use the host network's DNS
Correct answer: DNS queries are first checked against the cluster DNS (CoreDNS), with non-cluster queries forwarded upstream
ClusterFirst (the default) sends DNS queries to CoreDNS first; queries that don't match the cluster domain are forwarded to the upstream DNS configured on the node.
What is the valid port range for NodePort Services in Kubernetes?