Courseiva
Services and Networking →hardMultiple Select

CKAD Services and Networking Practice Question

Which TWO are valid ways to create a Service from a deployment named 'frontend'? (Choose two.)

⚠ Common exam trap

The CKAD exam often tests the distinction between creating a Service for an existing workload (via 'kubectl expose' or a YAML manifest) versus commands that create new resources ('kubectl create service', 'kubectl run --expose') or unrelated resources ('kubectl autoscale'), leading candidates to confuse 'expose' with 'create service' or 'autoscale'.

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

✓

Write a YAML manifest with apiVersion: v1, kind: Service, metadata.name, spec.selector matching deployment labels, and run kubectl apply -f manifest.yaml

It describes the standard method of creating a Kubernetes Service by writing a YAML manifest with the correct apiVersion (v1), kind (Service), metadata.name, and spec.selector that matches the labels of the target Pods (e.g., from the 'frontend' deployment). Running 'kubectl apply -f manifest.yaml' then creates the Service, which routes traffic to Pods with matching labels.

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 frontend --tcp=80:80

    Why it's wrong here

    kubectl create service clusterip frontend --tcp=80:80 creates a ClusterIP Service object named frontend with port 80, but it does not populate the spec.selector field. Without a selector matching the deployment's pod labels, the Service will have no Endpoints and will not forward traffic to the frontend deployment's pods. You would need to manually add a selector (e.g., --selector='app=frontend') or edit the Service after creation, making this an incomplete way to expose a deployment.

  • ✗

    kubectl autoscale deployment frontend --min=1 --max=5

    Why it's wrong here

    kubectl autoscale deployment frontend --min=1 --max=5 is used to create a HorizontalPodAutoscaler that adjusts the number of replicas based on observed CPU or memory utilization. This object has nothing to do with networking or stable service discovery; it does not create a Service or any network endpoint. While autoscaling is complementary to exposing a deployment, this command does not satisfy the requirement to expose it.

  • ✓

    Write a YAML manifest with apiVersion: v1, kind: Service, metadata.name, spec.selector matching deployment labels, and run kubectl apply -f manifest.yaml

    Why this is correct

    Writing a YAML manifest is the declarative and preferred approach because you explicitly specify apiVersion: v1, kind: Service, metadata.name, and spec.selector matching the labels defined in the deployment's pod template. After writing the manifest, running kubectl apply -f manifest.yaml creates or updates the Service on the cluster, and the selector ensures the Service's Endpoint controller tracks the backend pods. This method is idempotent and can be version-controlled.

  • ✓

    kubectl expose deployment frontend --port=80

    Why this is correct

    kubectl expose deployment frontend --port=80 is an imperative command that generates a Service based on the deployment's metadata. It automatically copies the labels from the deployment's spec.selector into the Service's spec.selector, ensuring traffic is routed to the pods managed by that deployment. The default type is ClusterIP, which provides an internal cluster IP and DNS name for the service.

  • ✗

    kubectl run frontend --image=nginx --port=80 --expose

    Why it's wrong here

    kubectl run frontend --image=nginx --port=80 --expose creates a brand new Deployment (in current kubectl) and a Service for it, rather than exposing the existing deployment named frontend. This command might overwrite or conflict with the existing resource name, and the generated Service selector may not match the labels of the original deployment's pods. Therefore, it creates a separate workload and Service instead of exposing an existing one.

About these practice questions

One of 826 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.