kubectl Services commands

22 commands in 3 groups: Manage, Expose & Port Forward, List & Inspect. Click or tap any command to copy it. Official documentation: kubernetes.io.

Open in the interactive cheat sheet search, stars and every other section

Manage

Create services imperatively or from manifests, edit, and remove them from the cluster.
kubectl apply -f service.yaml
Apply service from manifest
kubectl create svc clusterip <name> --tcp=80:8080
Create ClusterIP imperatively
kubectl create svc loadbalancer <name> --tcp=80:8080
Create LoadBalancer imperatively
kubectl create svc nodeport <name> --tcp=80:8080
Create NodePort imperatively
kubectl delete svc <name>
Delete a service
kubectl delete -f service.yaml
Delete service from manifest
kubectl delete svc --all -n <namespace>
Delete all services in namespace
kubectl edit svc <name>
Edit service in $EDITOR

Expose & Port Forward

Expose deployments as services or forward a local port for direct access without external exposure.
kubectl expose deploy/<name> --port=80 --target-port=8080
Create ClusterIP service
kubectl expose deploy/<name> --type=LoadBalancer --port=80
Create LoadBalancer service
kubectl expose deploy/<name> --type=NodePort --port=80
Create NodePort service
kubectl port-forward deploy/<name> <local>:<remote>
Forward local port to deployment
kubectl port-forward svc/<name> <local>:<remote>
Forward local port to service

List & Inspect

View services, their type, cluster IP, ports, and resolved endpoints.
kubectl describe svc <name>
Service details, selectors, endpoints
kubectl get endpointslices
EndpointSlice API, replaces the deprecated Endpoints
kubectl get ep
Short alias for get endpoints (API deprecated since v1.33)
kubectl get services
List services in current namespace
kubectl get endpointslices -l kubernetes.io/service-name=<name>
View EndpointSlices backing a service
kubectl get svc -A
All services across namespaces
kubectl get svc -n <namespace>
Services in a specific namespace
kubectl get svc -o wide
Services plus the Selector column
kubectl get svc <name> -o yaml
Get service manifest as YAML