WebMagicInformatica
CKAD practice questions

CKAD practice questions: Services and Networking

5 free questions on Services and Networking, 20% of the Kubernetes: CKAD exam. Try each one, then open the answer and explanation. None of them are in the free readiness check, so you can still take it fresh.

Question 1

A Service has targetPort: http. The container defines:

ports:
- name: web
  containerPort: 8080

Connections through the Service fail. What is wrong?

  1. A.

    Named ports are not allowed in targetPort.

  2. B.

    containerPort must be 80 for named ports to work.

  3. C.

    The container needs hostPort: 8080.

  4. D.

    The Service refers to a named port http, but the container's port is named web; use targetPort: web (or 8080).

Show answer and explanation

Answer: D

A named targetPort must match the port name defined in the Pod's container. Here the names differ, so no port resolves.

  • Named target ports are supported.
  • Any container port number may be named.
  • hostPort is not needed for Service routing.
Question 2

From your laptop you want to reach port 80 of the Service web through local port 8080 for a quick test. Which command does this?

  1. A.

    kubectl port-forward service/web 8080:80

  2. B.

    kubectl port-forward service/web 80:8080

  3. C.

    kubectl proxy 8080:80

  4. D.

    kubectl expose service web --port=8080

Show answer and explanation

Answer: A

port-forward uses LOCAL:REMOTE, so 8080:80 forwards local port 8080 to port 80 of the Service's backing Pod.

  • The reversed form forwards local port 80 to remote 8080.
  • kubectl proxy proxies the API server and takes a single --port.
  • expose creates a new Service.
Question 3

A NetworkPolicy must allow ingress to the app=api Pods only from the namespace monitoring. The namespaces have no custom labels. Which from entry works?

  1. A.
    from:
    - namespaceSelector:
        matchLabels:
          name: monitoring
  2. B.
    from:
    - podSelector:
        matchLabels:
          namespace: monitoring
  3. C.
    from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: monitoring
  4. D.
    from:
    - ipBlock:
        cidr: monitoring
Show answer and explanation

Answer: C

Every namespace automatically has the label kubernetes.io/metadata.name equal to its name, so it can be selected without adding labels.

  • A name label exists only if someone added it.
  • A podSelector matches Pod labels in the policy's own namespace.
  • ipBlock requires a CIDR, not a name.
Question 4

Which command creates an Ingress web (class nginx) that sends shop.example.com/cart and everything below it to Service cart-svc port 80?

  1. A.

    kubectl create ingress web --class=nginx --rule="cart-svc:80=shop.example.com/cart*"

  2. B.

    kubectl create ingress web --class=nginx --host=shop.example.com --path=/cart --service=cart-svc

  3. C.

    kubectl create ingress web --class=nginx --rule="shop.example.com/cart*=cart-svc:80"

  4. D.

    kubectl create ingress web --class=nginx --rule="shop.example.com/cart=cart-svc"

Show answer and explanation

Answer: C

The rule format is host/path=service:port; a trailing * on the path creates a Prefix match (without it the path is Exact).

  • The first alternative reverses both sides.
  • --host, --path and --service are not flags.
  • The last form lacks the port and would be Exact.
Question 5

Requests from the same client IP should keep reaching the same backend Pod of a Service. Which Service setting does this?

  1. A.

    externalTrafficPolicy: Local

  2. B.

    sessionAffinity: ClientIP

  3. C.

    internalTrafficPolicy: Local

  4. D.

    publishNotReadyAddresses: true

Show answer and explanation

Answer: B

sessionAffinity: ClientIP makes kube-proxy route connections from one client IP to the same Pod (for a configurable timeout).

  • The traffic policies control whether traffic stays on the node.
  • publishNotReadyAddresses includes unready Pods in DNS and endpoints.

How ready are you for CKAD?

Take the free readiness check: 15 questions from every exam domain in 20 minutes, with your score per domain.

  • 20 minutes
  • 15 questions
  • Free with an account

More CKAD practice by topic

Back to the CKAD practice test →

Independent practice material written from the official exam guide. Not affiliated with or endorsed by the exam provider.