Courseiva
Services and NetworkingmediumMultiple ChoiceObjective-mapped

CKA Services and Networking Practice Question

You want to expose a Deployment named 'web' on port 80 internally within the cluster. Which command creates a ClusterIP Service?

⚠ Common exam trap

Candidates often think `kubectl create service clusterip` is the correct way to expose an existing Deployment, but it creates an orphaned Service without linking to the Deployment's Pods, whereas `kubectl expose` correctly derives the selector from the Deployment.

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 web --port=80 --type=ClusterIP

`kubectl expose deployment web --port=80 --type=ClusterIP` creates a ClusterIP Service that exposes the Deployment named 'web' on port 80 internally within the cluster. The `--type=ClusterIP` is the default service type, making this command explicitly create a ClusterIP Service, which is only reachable from inside the Kubernetes cluster.

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 web --port=80 --type=ClusterIP

    Why this is correct

    `kubectl expose deployment web --port=80 --type=ClusterIP` is the canonical imperative command for exposing a Deployment as a Service. It reads the Deployment's pod selector (e.g., `app=web`), creates a ClusterIP Service named `web` with `port=80`, and sets the Service's targetPort to the same value unless overridden. This automatically gains an Endpoints object pointing at the Deployment's healthy pods, which is exactly what "exposing" a Deployment means on the internal cluster network.

  • kubectl create deployment web --image=nginx --port=80

    Why it's wrong here

    `kubectl create deployment web --image=nginx --port=80` provisions a Deployment object, not a Service. The `--port` flag here merely sets the `containerPort` in the Pod template for documentation/readiness purposes; it has no effect on network reachability from outside the Pod. The Deployment creates Pods with Nginx listening on port 80, but without a Service object those Pods have no stable virtual IP and are not truly "exposed" to other workloads.

  • kubectl run web --image=nginx --port=80

    Why it's wrong here

    `kubectl run web --image=nginx --port=80` in current kubectl versions creates a standalone Pod (in newer versions it does not even create a Deployment), and again `--port` specifies the container port, not a Service port. A Pod's IP is ephemeral and not routable via a stable Service DNS name. To expose this Pod you would still need a Service, and the question specifically asks to expose an existing Deployment, not to create a Pod.

  • kubectl create service clusterip web --tcp=80:80

    Why it's wrong here

    `kubectl create service clusterip web --tcp=80:80` does create a ClusterIP Service, but it does not expose the existing Deployment `web`. The command generates a Service with a default selector (typically `app=web`) and does not read or inherit the Deployment's label selectors; if the Deployment's Pods use different labels, the Service will have no endpoints. The correct workflow is to describe the Deployment and let `kubectl expose` derive the selector, or to explicitly pass `--selector` and `--target-port` matching the Deployment's Pod template.

About these practice questions

One of 302 original CKA practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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 CKA 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 CKA exam.