CKAD · Domain 5 of 5 · 20% of the exam

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

  1. Question 1. A Service selects app=web, but its Pods are labeled app=Web. What happens?

    1. Labels are case-insensitive, so it works
    2. The Service has no endpoints, because labels are case-sensitive
    3. The Service routes to every Pod in the namespace
    4. The Pods fail to start
    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.

  2. Question 2. Why might a Service use targetPort: http rather than a number?

    1. It refers to a named container port, so the number can change
    2. It tells kube-proxy to inspect HTTP headers
    3. It makes the Service accept HTTPS too
    4. It's required for Ingress backends
    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.

  3. Question 3. Which command lists the EndpointSlices behind Service web?

    1. kubectl get endpointslices web --all-namespaces
    2. kubectl describe pods -l service-name=web
    3. kubectl get endpointslices -l kubernetes.io/service-name=web
    4. kubectl get svc web -o endpointslices
    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.

  4. Question 4. From a Pod in the same namespace, which name reaches Service api?

    1. api.cluster
    2. svc-api.local
    3. api.pod.local
    4. 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>.

  5. Question 5. What does sessionAffinity: ClientIP do on a Service?

    1. Keeps the client's source IP in packets
    2. Sends each client's requests to the same Pod
    3. Lets only listed client IPs connect
    4. Gives each client its own ClusterIP
    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.

  6. Question 6. A Service is defined without a selector. How does it get endpoints?

    1. kube-proxy finds Pods with a matching name
    2. It routes to every Pod in the namespace
    3. You create EndpointSlices for it yourself
    4. It can't be used until a selector is added
    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.

  7. Question 7. Which command creates a ClusterIP Service for Pod db on port 5432?

    1. kubectl expose pod db --port=5432
    2. kubectl create service pod db --port=5432
    3. kubectl port-forward pod/db 5432 --service
    4. kubectl create svc db --pod=db 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.

  8. Question 8. Which command creates a NodePort Service named web on port 80 that forwards to container port 8080?

    1. kubectl create service web --type=NodePort --port=80
    2. kubectl create service nodeport web --tcp=80:8080
    3. kubectl expose service web --nodeport=80
    4. kubectl create nodeport web --tcp=80: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.

  9. Question 9. A Service has port: 80 and targetPort: 8080. A client inside the cluster connects to which port?

    1. 8080 on the ClusterIP
    2. Any NodePort on the node
    3. 80 on each Pod's IP
    4. 80 on the Service's ClusterIP
    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.

  10. Question 10. A Service works, but one of its Pods never gets traffic, though its labels match. What is a likely cause?

    1. The Pod isn't Ready, so it isn't a serving endpoint
    2. The Pod uses a different image tag
    3. The Pod has no resource limits
    4. The Pod runs on a different node
    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.

  11. Question 11. A Pod in namespace web calls http://orders, but Service orders is in namespace shop. What fixes it?

    1. Add a NetworkPolicy that allows DNS
    2. Create a NodePort for orders
    3. Call orders.shop or the full DNS name
    4. Restart CoreDNS in kube-system
    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.

  12. Question 12. With the default cluster domain, what is the full DNS name of Service orders in namespace shop?

    1. orders.svc.shop.cluster.local
    2. shop.orders.svc.cluster.local
    3. orders.shop.cluster.svc.local
    4. orders.shop.svc.cluster.local
    Show answer

    Answer: D. orders.shop.svc.cluster.local

    The pattern is <service>.<namespace>.svc.<cluster-domain>.

  13. Question 13. A NetworkPolicy ingress rule has namespaceSelector and podSelector in the same from element. What does it allow?

    1. Pods matching either selector
    2. Pods matching both selectors together
    3. All Pods in the matching namespaces
    4. Nothing; the rule is invalid
    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.

  14. Question 14. An ingress rule's from list has two separate elements: one namespaceSelector and one podSelector. What does it allow?

    1. Only traffic that matches both
    2. Only the first element
    3. Traffic that matches either element
    4. Nothing; elements can't be mixed
    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.

  15. Question 15. Which NetworkPolicy denies all egress from every Pod in its namespace?

    1. podSelector: {} with egress: [{}]
    2. policyTypes: [Ingress] with an empty ingress list
    3. podSelector: {} with policyTypes: [Egress] and no egress rules
    4. A policy with egress: deny-all
    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.

  16. Question 16. Two NetworkPolicies select the same Pod: one allows ingress on port 80 and the other on port 443. What is allowed?

    1. Only the policy created last
    2. Neither, because conflicting policies deny all
    3. Only the policy whose name sorts first
    4. Both ports, because policies add together
    Show answer

    Answer: D. Both ports, because policies add together

    NetworkPolicies are allow-lists and are unioned. There are no deny rules to conflict.

  17. Question 17. Which egress rule allows traffic to 10.0.0.0/16 except 10.0.5.0/24?

    1. ipBlock with cidr 10.0.0.0/16 and except 10.0.5.0/24
    2. Two ipBlocks, one of them with deny: true
    3. namespaceSelector with a cidr label
    4. podSelector with an ipRange field
    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.

  18. Question 18. An egress policy for app=web now allows only traffic to app=db, and DNS lookups fail. What must you also allow?

    1. Port 443 over TCP to the API server
    2. Port 53 over UDP and TCP to the cluster DNS
    3. Port 5353 over TCP to every node
    4. Port 8053 over UDP to kube-proxy
    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.

  19. Question 19. How do you restrict a NetworkPolicy ingress rule to TCP port 5432?

    1. targetPort: 5432 in the podSelector
    2. allowPorts: [5432] at policy level
    3. A Service of port 5432 in the rule
    4. ports with protocol: TCP and 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.

  20. Question 20. How does one NetworkPolicy rule allow the port range 8000 to 8100?

    1. portRange: 8000-8100
    2. port: 8000 with endPort: 8100
    3. port: 8000 with maxPort: 8100
    4. ports: [8000..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.

  21. Question 21. A NetworkPolicy has policyTypes: [Ingress] only. What happens to egress from the Pods it selects?

    1. Egress is unaffected and still allowed
    2. Egress is denied by default
    3. Egress is limited to the same namespace
    4. Egress is only allowed to Services
    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.

  22. Question 22. How can a NetworkPolicy select namespace prod when nobody added custom labels to it?

    1. Use namespace: prod inside the podSelector
    2. Use a namespaceName: prod field in the rule
    3. It can't, so a label must be added first
    4. Match the kubernetes.io/metadata.name: prod label
    Show answer

    Answer: D. Match the kubernetes.io/metadata.name: prod label

    Kubernetes sets the immutable label kubernetes.io/metadata.name on every namespace.

  23. Question 23. Which podSelector in a NetworkPolicy selects every Pod in its namespace?

    1. podSelector: '*'
    2. podSelector: all
    3. podSelector: {}
    4. podSelector: {matchLabels: all}
    Show answer

    Answer: C. podSelector: {}

    An empty selector matches everything in the policy's namespace.

  24. Question 24. Which command tests whether Pod client can reach Service api on port 8080?

    1. kubectl exec client -- wget -qO- -T 2 api:8080
    2. kubectl port-forward client api:8080
    3. kubectl get svc api --test
    4. kubectl describe netpol api --from=client
    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.

  25. Question 25. After a default-deny ingress policy, which policy restores traffic from app=web to app=api?

    1. One selecting app=web, with ingress from app=api
    2. One selecting app=api, with ingress from podSelector app=web
    3. One selecting app=api, with egress to app=web
    4. Removing the label app=api from the Pods
    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.

  26. Question 26. A default-deny egress policy blocks traffic from app=web to app=api. Ingress isn't restricted. What is needed?

    1. An ingress rule on app=web allowing app=api
    2. An egress rule on app=api allowing app=web
    3. An egress rule on app=web allowing app=api
    4. A NodePort Service for app=api
    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.

  27. Question 27. Which command creates an Ingress that sends shop.example.com/cart to Service cart on port 80?

    1. kubectl expose ingress shop --host=shop.example.com --svc=cart
    2. kubectl create ingress shop --backend=cart:80 --path=shop.example.com
    3. kubectl create route shop --rule=shop.example.com/cart=cart:80
    4. kubectl create ingress shop --rule=shop.example.com/cart=cart: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.

  28. Question 28. An Ingress rule has pathType: Exact and path: /api. Which requests match?

    1. /api only, not /api/ or /api/v1
    2. /api and anything under it
    3. /api, /API, and /Api
    4. Any path containing api
    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.

  29. Question 29. With pathType: Prefix and path: /app, does a request for /application match?

    1. Yes, any string prefix matches
    2. No, because Prefix matches whole path segments
    3. Only if the rule also sets a host
    4. Only with a rewrite annotation
    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.

  30. Question 30. Which part of an Ingress handles requests that match none of its rules?

    1. The first rule in the list
    2. The Service with the most Pods
    3. The defaultBackend, if one is set
    4. kube-proxy on the receiving node
    Show answer

    Answer: C. The defaultBackend, if one is set

    Without a defaultBackend, the controller's own default behaviour applies, usually a 404.

  31. Question 31. In a networking.k8s.io/v1 Ingress, which backend fields point to a Service?

    1. serviceName and servicePort
    2. backend.pod and backend.containerPort
    3. target.svc and target.port
    4. service.name and service.port.number
    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.

  32. Question 32. An Ingress's tls section sets secretName: web-tls. What must that Secret contain?

    1. Keys tls.crt and tls.key, in the same namespace
    2. A CA bundle in kube-system
    3. A token for the Ingress controller
    4. A ConfigMap reference to the certificate
    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.

  33. Question 33. An Ingress controller returns 404 for requests to shop.example.com. What should you check first?

    1. That the Service type is LoadBalancer
    2. That a rule's host matches the request's Host header
    3. That the Pods have resource limits
    4. That kube-proxy runs in IPVS mode
    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.

  34. Question 34. What makes an IngressClass the default for Ingresses that don't set ingressClassName?

    1. Naming the IngressClass default
    2. Setting priority: 0 on the IngressClass
    3. The ingressclass.kubernetes.io/is-default-class annotation
    4. Creating it in kube-system
    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.

  35. Question 35. What is true of annotations such as nginx.ingress.kubernetes.io/rewrite-target?

    1. Every Ingress controller supports them
    2. They're part of the Ingress API schema
    3. kube-proxy applies them
    4. Each one is specific to a particular controller
    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.

  36. Question 36. One Ingress must send api.example.com to Service api and www.example.com to Service web. How?

    1. Two rules, each with its own host
    2. Two Ingresses that share one path
    3. One rule with two backends
    4. A Service with two selectors
    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.

  37. Question 37. Which Service type do Ingress backends normally use?

    1. ExternalName
    2. ClusterIP
    3. LoadBalancer
    4. Headless only
    Show answer

    Answer: B. ClusterIP

    The Ingress controller runs in the cluster and reaches backends internally, so a ClusterIP Service is enough.

  38. Question 38. Which address do clients use to reach apps exposed through an Ingress?

    1. Each backend Pod's IP
    2. The backend Service's ClusterIP
    3. The Ingress controller's external address
    4. The API server's address
    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.

  39. Question 39. Which command shows an Ingress's rules together with their backend Services and endpoints?

    1. kubectl get ingress shop --rules
    2. kubectl logs ingress/shop
    3. kubectl get endpoints ingress/shop
    4. kubectl describe ingress shop
    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.

  40. Question 40. Which command shows whether Ingress shop has been given an address by its controller?

    1. kubectl get ingress shop
    2. kubectl get ingressclass shop
    3. kubectl top ingress shop
    4. kubectl get svc shop -o wide
    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.