Exposing and Examining a Service

Expose the port of the service

Linux shell command

export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')

Windows shell command

$Env:NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')

Use curl the view a response from the service

Linux shell command

curl $(minikube ip):$NODE_PORT

Windows shell command

curl "$(minikube ip):$Env:NODE_PORT"


View the content of a deployment

shell command

kubectl describe deployment


View the content of a single pod

shell command

kubectl get pods -l run=kubernetes-bootcamp


View the content of a single service

shell command

kubectl get services -l run=kubernetes-bootcamp


Get the name of the POD

Linux shell command

export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')

Windows shell command

$Env:POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{end}}')

Seeing all information on a service

Windows shell command

kubectl get all

Seeing detailed information about a deployment

Windows shell command

kubectl get deploy/<service name> -o yaml


Change a label within a POD

Linux shell command

kubectl label pod $POD_NAME app=v1


Windows shell command

kubectl label pod $Env:POD_NAME app=v1

Describe POD using pod name

Linux shell command

kubectl describe pods $POD_NAME

Windows shell command

kubectl describe pods $Env:POD_NAME

Using value of POD get a particular POD

kubectl get pods -l app=v1


Delete a service

kubectl delete service -l run=kubernetes-bootcamp


Confirm service has been deleted

kubectl get services

The next command proves that the app is not reachable from the outside


Linux shell command

curl $(minikube ip):$NODE_PORT

Windows shell command

curl "$(minikube ip):$Env:NODE_PORT"

The next command proves that the app is still up and running

Linux shell command

kubectl exec -ti $POD_NAME curl localhost:8080

Windows shell command

kubectl exec -ti $Env:POD_NAME curl localhost:8080