Question 5
Domain 4: Services, Networking, and Service DiscoveryWhich Kubernetes command creates a Service exposing an existing Deployment on port 6262 and lets you verify the Service and its Endpoints?
Correct answer: A
Explanation
`kubectl expose deployment <deployment-name> --port=6262 --target-port=6262` creates a Service from an existing Deployment and maps the Service port to the container port, matching the requested 6262. `kubectl get svc && kubectl get endpoints` then verifies the Service and its Endpoints, since Endpoints show the pods selected by the Service.
Why each option is right or wrong
A. kubectl expose deployment <deployment-name> --port=6262 --target-port=6262 && kubectl get svc && kubectl get endpoints
`kubectl expose deployment <deployment-name>` is the Kubernetes subcommand that generates a Service object from an existing Deployment, and `--port=6262` sets the Service’s listening port while `--target-port=6262` maps traffic to the same container port 6262. The follow-up `kubectl get svc && kubectl get endpoints` is the correct verification step because `get svc` confirms the Service resource exists, and `get endpoints` shows the backing pod IPs selected by that Service, which is how Kubernetes records the live endpoint set.
B. kubectl create service clusterip <deployment-name> --tcp=6262:6262 && kubectl get pods && kubectl describe deployment <deployment-name>
C. kubectl expose pod <deployment-name> --port=6262 --type=LoadBalancer && kubectl get ingress && kubectl get endpointslices
D. kubectl set service deployment/<deployment-name> port=6262 && kubectl get svc && kubectl get rs