Courseiva
Services and NetworkingmediumMultiple ChoiceObjective-mapped

CKAD Services and Networking Practice Question

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

⚠ Common exam trap

Many candidates confuse `kubectl create service clusterip` with `kubectl expose`; the former creates a Service without linking it to a workload, while the latter creates a Service that automatically selects the pods of the specified resource, which is required to expose the Deployment's pods internally.

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

The `kubectl expose deployment web --port=80` command creates a Service of type ClusterIP by default, which exposes the Deployment's pods on port 80 internally within the cluster. This matches the requirement to expose the 'web' Deployment on port 80 internally without specifying a target port, as it defaults to the container's port defined in the Deployment.

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 create service clusterip web --tcp=80:80

    Why it's wrong here

    kubectl create service clusterip web --tcp=80:80 generates a ClusterIP Service, but it does not inspect the Deployment's pod template. It assigns an auto-generated selector (typically app=web) rather than copying the Deployment's actual labels, so the Service may not match the Pods managed by the Deployment. Consequently, the Service would have no endpoints and traffic would not reach the web Deployment.

  • kubectl expose deployment web --port=80

    Why this is correct

    kubectl expose deployment web --port=80 is the imperative command that creates a ClusterIP Service directly from the Deployment object. kubectl extracts the labels defined in the Deployment's pod template and sets them as the Service's selector, guaranteeing the Service routes traffic to exactly those Pods. It also maps port 80 to the Pods' targetPort, which defaults to 80 if not specified. This is the intended one-line solution.

  • kubectl apply -f service.yaml

    Why it's wrong here

    kubectl apply -f service.yaml could potentially create a Service, but it requires an existing manifest file with a selector that exactly matches the Deployment's pod labels. Since the file's contents are not provided, you cannot be certain the Service targets the correct Pods; additionally, the question specifically asks for a command to expose the Deployment, not to apply a pre-written file. Thus, this is not a valid single-command solution.

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

    Why it's wrong here

    kubectl run web --image=nginx --port=80 attempts to create a standalone Pod (or Deployment in some contexts) named web, not a Service. It does not modify or expose the existing Deployment; it would likely conflict or create a separate resource. Even if it succeeds, it provides no stable ClusterIP or DNS endpoint for the existing web Deployment, so it fails to satisfy the requirement.

About these practice questions

One of 160 original CKAD 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 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.