CKAD Domain 5: Services and Networking
40 free practice questions for Services and Networking in the Certified Kubernetes Application Developer (CKAD) exam. Try each question first, then open "Show answer" for the correct option and explanation.
Services and Networking practice questions
-
Question 1. A Service selects app=web, but its Pods are labeled app=Web. What happens?
Show answer
Answer: B. The Service has no endpoints, because labels are case-sensitive
Label keys and values are compared exactly. kubectl get pods --show-labels next to the Service's selector shows the mismatch.
-
Question 2. Why might a Service use targetPort: http rather than a number?
Show answer
Answer: A. It refers to a named container port, so the number can change
The name resolves to the containerPort named http in each Pod, so Pods can change the port number without editing the Service.
-
Question 3. Which command lists the EndpointSlices behind Service web?
Show answer
Answer: C. kubectl get endpointslices -l kubernetes.io/service-name=web
EndpointSlices are labeled with the name of the Service they belong to.
-
Question 4. From a Pod in the same namespace, which name reaches Service api?
Show answer
Answer: D. api
The Pod's DNS search path includes its own namespace, so the short name resolves. Other namespaces need api.<namespace>.
-
Question 5. What does sessionAffinity: ClientIP do on a Service?
Show answer
Answer: B. Sends each client's requests to the same Pod
kube-proxy pins a client IP to one backend Pod, for up to 3 hours by default.
-
Question 6. A Service is defined without a selector. How does it get endpoints?
Show answer
Answer: C. You create EndpointSlices for it yourself
Selector-less Services can point at backends outside the cluster or in another namespace through manually managed EndpointSlices.
-
Question 7. Which command creates a ClusterIP Service for Pod db on port 5432?
Show answer
Answer: A. kubectl expose pod db --port=5432
kubectl expose copies the Pod's labels into the Service selector. The Pod must have labels for this to work.
-
Question 8. Which command creates a NodePort Service named web on port 80 that forwards to container port 8080?
Show answer
Answer: B. kubectl create service nodeport web --tcp=80:8080
kubectl create service <type> sets a selector of app=<name>; --tcp takes port:targetPort.
-
Question 9. A Service has port: 80 and targetPort: 8080. A client inside the cluster connects to which port?
Show answer
Answer: D. 80 on the Service's ClusterIP
Clients use port on the Service. Traffic is then forwarded to targetPort on the selected Pods.
-
Question 10. A Service works, but one of its Pods never gets traffic, though its labels match. What is a likely cause?
Show answer
Answer: A. The Pod isn't Ready, so it isn't a serving endpoint
Pods that fail readiness are marked not ready in the EndpointSlice and get no traffic until they pass.
-
Question 11. A Pod in namespace web calls http://orders, but Service orders is in namespace shop. What fixes it?
Show answer
Answer: C. Call orders.shop or the full DNS name
A short name only resolves in the caller's own namespace. orders.shop or orders.shop.svc.cluster.local works from anywhere.
-
Question 12. With the default cluster domain, what is the full DNS name of Service orders in namespace shop?
Show answer
Answer: D. orders.shop.svc.cluster.local
The pattern is <service>.<namespace>.svc.<cluster-domain>.
-
Question 13. A NetworkPolicy ingress rule has namespaceSelector and podSelector in the same from element. What does it allow?
Show answer
Answer: B. Pods matching both selectors together
In one element, the selectors are ANDed: matching Pods in matching namespaces. YAML indentation decides this, so a stray dash changes the meaning.
-
Question 14. An ingress rule's from list has two separate elements: one namespaceSelector and one podSelector. What does it allow?
Show answer
Answer: C. Traffic that matches either element
Separate list elements are ORed. The podSelector element alone means Pods in the policy's own namespace.
-
Question 15. Which NetworkPolicy denies all egress from every Pod in its namespace?
Show answer
Answer: C. podSelector: {} with policyTypes: [Egress] and no egress rules
An empty podSelector selects all Pods, and Egress with no rules allows nothing. egress: [{}] would allow all egress.
-
Question 16. Two NetworkPolicies select the same Pod: one allows ingress on port 80 and the other on port 443. What is allowed?
Show answer
Answer: D. Both ports, because policies add together
NetworkPolicies are allow-lists and are unioned. There are no deny rules to conflict.
-
Question 17. Which egress rule allows traffic to 10.0.0.0/16 except 10.0.5.0/24?
Show answer
Answer: A. ipBlock with cidr 10.0.0.0/16 and except 10.0.5.0/24
ipBlock.except carves ranges out of the CIDR. ipBlock is meant for addresses outside the cluster; Pod IPs are better matched by selectors.
-
Question 18. An egress policy for app=web now allows only traffic to app=db, and DNS lookups fail. What must you also allow?
Show answer
Answer: B. Port 53 over UDP and TCP to the cluster DNS
Name lookups go to CoreDNS (kube-dns) on port 53, mostly UDP with TCP for large answers.
-
Question 19. How do you restrict a NetworkPolicy ingress rule to TCP port 5432?
Show answer
Answer: D. ports with protocol: TCP and port: 5432
Each rule can list ports. Without ports, the rule allows all ports from the listed peers.
-
Question 20. How does one NetworkPolicy rule allow the port range 8000 to 8100?
Show answer
Answer: B. port: 8000 with endPort: 8100
endPort is valid only with a numeric port and must be at least port. Not every network plugin supports it.
-
Question 21. A NetworkPolicy has policyTypes: [Ingress] only. What happens to egress from the Pods it selects?
Show answer
Answer: A. Egress is unaffected and still allowed
Only the listed policy types are isolated. Egress stays open unless another policy selects the Pods for Egress.
-
Question 22. How can a NetworkPolicy select namespace prod when nobody added custom labels to it?
Show answer
Answer: D. Match the kubernetes.io/metadata.name: prod label
Kubernetes sets the immutable label kubernetes.io/metadata.name on every namespace.
-
Question 23. Which podSelector in a NetworkPolicy selects every Pod in its namespace?
Show answer
Answer: C. podSelector: {}
An empty selector matches everything in the policy's namespace.
-
Question 24. Which command tests whether Pod client can reach Service api on port 8080?
Show answer
Answer: A. kubectl exec client -- wget -qO- -T 2 api:8080
Running a request from the client Pod tests DNS, Service routing, and NetworkPolicy along the real path.
-
Question 25. After a default-deny ingress policy, which policy restores traffic from app=web to app=api?
Show answer
Answer: B. One selecting app=api, with ingress from podSelector app=web
The policy selects the destination Pods (app=api) and lists the allowed sources in ingress.from.
-
Question 26. A default-deny egress policy blocks traffic from app=web to app=api. Ingress isn't restricted. What is needed?
Show answer
Answer: C. An egress rule on app=web allowing app=api
Egress is controlled on the sender. If app=api were also ingress-isolated, it would need a matching ingress rule too.
-
Question 27. Which command creates an Ingress that sends shop.example.com/cart to Service cart on port 80?
Show answer
Answer: D. kubectl create ingress shop --rule=shop.example.com/cart=cart:80
--rule takes host/path=service:port. Add * to the path for a Prefix match, and ,tls=secret for TLS.
-
Question 28. An Ingress rule has pathType: Exact and path: /api. Which requests match?
Show answer
Answer: A. /api only, not /api/ or /api/v1
Exact matches the path exactly and is case-sensitive. Prefix matches /api and /api/v1.
-
Question 29. With pathType: Prefix and path: /app, does a request for /application match?
Show answer
Answer: B. No, because Prefix matches whole path segments
Prefix compares element by element split on /, so /app matches /app and /app/x, but not /application.
-
Question 30. Which part of an Ingress handles requests that match none of its rules?
Show answer
Answer: C. The defaultBackend, if one is set
Without a defaultBackend, the controller's own default behaviour applies, usually a 404.
-
Question 31. In a networking.k8s.io/v1 Ingress, which backend fields point to a Service?
Show answer
Answer: D. service.name and service.port.number
serviceName and servicePort are from the removed v1beta1 API. In v1, use service.port.number or service.port.name.
-
Question 32. An Ingress's tls section sets secretName: web-tls. What must that Secret contain?
Show answer
Answer: A. Keys tls.crt and tls.key, in the same namespace
The Secret is of type kubernetes.io/tls and must be in the Ingress's namespace.
-
Question 33. An Ingress controller returns 404 for requests to shop.example.com. What should you check first?
Show answer
Answer: B. That a rule's host matches the request's Host header
If no host and path match, the controller falls back to its default 404. Testing with curl -H 'Host: shop.example.com' helps.
-
Question 34. What makes an IngressClass the default for Ingresses that don't set ingressClassName?
Show answer
Answer: C. The ingressclass.kubernetes.io/is-default-class annotation
Set the annotation to "true" on exactly one IngressClass. New Ingresses without a class then get it filled in.
-
Question 35. What is true of annotations such as nginx.ingress.kubernetes.io/rewrite-target?
Show answer
Answer: D. Each one is specific to a particular controller
Annotations carry controller-specific settings. Switching controllers means translating them, which is one reason the Gateway API exists.
-
Question 36. One Ingress must send api.example.com to Service api and www.example.com to Service web. How?
Show answer
Answer: A. Two rules, each with its own host
Each entry in rules can set a host and its own paths and backends.
-
Question 37. Which Service type do Ingress backends normally use?
Show answer
Answer: B. ClusterIP
The Ingress controller runs in the cluster and reaches backends internally, so a ClusterIP Service is enough.
-
Question 38. Which address do clients use to reach apps exposed through an Ingress?
Show answer
Answer: C. The Ingress controller's external address
Clients reach the controller, for example through its LoadBalancer Service, and the controller routes by host and path.
-
Question 39. Which command shows an Ingress's rules together with their backend Services and endpoints?
Show answer
Answer: D. kubectl describe ingress shop
describe lists each host and path with its backend and the Pod IPs behind it, plus events from the controller.
-
Question 40. Which command shows whether Ingress shop has been given an address by its controller?
Show answer
Answer: A. kubectl get ingress shop
The ADDRESS column fills in once the controller has processed the Ingress.
CKAD, Certified Kubernetes Application Developer, and Kubernetes are trademarks of The Linux Foundation. These questions are original study material, not questions from the real exam.