Courseiva
Services and NetworkingeasyMultiple ChoiceObjective-mapped

CKAD Services and Networking Practice Question

Which of the following commands creates a ClusterIP service named 'my-service' that exposes port 80 on the pod with label 'app=web'?

⚠ Common exam trap

Test-takers frequently think `kubectl create service clusterip` is the correct way to create a ClusterIP service with a selector, but it actually creates a service without a selector, requiring manual label specification via `--selector` or a YAML definition.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

kubectl expose deployment my-deployment --port=80 --name=my-service

`kubectl expose deployment my-deployment --port=80 --name=my-service` creates a ClusterIP service by default, which selects pods based on the labels of the deployment (e.g., `app=web` if the deployment has that label). The `--port=80` flag sets the service port, and the service automatically maps to the container port (defaults to the same port if `--target-port` is omitted). This command satisfies the requirement of exposing port 80 on pods with label `app=web`.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • kubectl expose deployment my-deployment --port=80 --name=my-service

    Why this is correct

    The `kubectl expose deployment my-deployment --port=80 --name=my-service` command correctly creates a ClusterIP service by default because no `--type` flag is specified, so it defaults to `ClusterIP`. It also infers the selector from the deployment's pod template labels (e.g., `app=web`) and sets the service's target port to the container's port (defaulting to 80), allowing automatic traffic routing to the pods managed by the deployment.

  • kubectl expose pod my-pod --port=80 --target-port=8080 --name=my-service

    Why it's wrong here

    This command exposes a specific pod, not using a label selector. Also, '--target-port' is not a standard flag; it should be '--target-port=8080'? Actually '--target-port' is valid but the question asks for a service exposing port 80 with pod label 'app=web'.

  • kubectl create service clusterip my-service --tcp=80:8080 --cluster-ip=10.0.0.1

    Why it's wrong here

    Although `kubectl create service clusterip my-service --tcp=80:8080 --cluster-ip=10.0.0.1` does create a Service of type ClusterIP, it does not include a selector to match the deployment's pods (`app=web`). Without a selector, the Service cannot automatically discover endpoints; you would have to manually create EndpointSlices, which is not the intended behavior for exposing a deployment. Additionally, setting `--cluster-ip=10.0.0.1` explicitly assigns a specific IP that may be outside the configured service CIDR or conflict with a reserved address, making this command both operationally unsuitable and not equivalent to `kubectl expose`.

  • kubectl expose deployment my-deployment --type=NodePort --port=80 --name=my-service

    Why it's wrong here

    The command `kubectl expose deployment my-deployment --type=NodePort --port=80 --name=my-service` explicitly overrides the default Service type to `NodePort`, which is not a ClusterIP service. A NodePort Service actually creates a ClusterIP as a sub-resource, but the Service's primary type is NodePort, meaning it exposes the service on a static port on every node (30000-32767). Since the question asks for a ClusterIP service, the `--type=NodePort` flag causes the command to produce a Service of the wrong type, even though it otherwise selects the deployment's pods correctly.

About these practice questions

Courseiva writes every CKAD question from scratch — 160 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This CKAD practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CKAD exam.