Kubernetes

Commands

kubectl get all

Get information about all pods:

kubectl get pods

Get information about all pods, including information on their IP, Node, and Readiness status:

kubectl get pods -o wide

Create resources from a manifest file:

kubectl apply -f manifest.yaml

Delete resources from a manifest file:

kubectl delete -f manifest.yaml

Finding a hard-to-find pod, a common reason is because it's in a different namespace:

kubectl get pods --all-namespaces

You can execute an arbitrary code on a running pod:

kubectl exec pod/name-of-pod -- ls

You can launch an interactive shell in a running pod:

kubectl exec -it pod/name-of-pod -- bash

List all of the namespaces:

# Long form
kubectl get namespaces

# Short form
kubectl get ns

Show me everything, everywhere:

# Short form
kubectl get all -A

# Long form
kubectl get all --all-namespaces

Export the manifest for the pod nginx-pod in the namespace troubleshooting YAML format

kubectl describe pod nginx-pod --namespace troubleshooting -o yaml

Probes

Configure Liveness, Readiness and Startup Probes

The kubelet uses liveness probes to know when to restart a container.

Q&A

Question: What is the one thing that connects a service to a pod? Answer: A label. A service has a selector. That selector must match a label on a pod.


So there's "pods" and there's "services". You can kubectl describe pod and you can kubectl describe service.

Question: In the manifest: what is the difference between the "Port", the "NodePort", and the "TargetPort"?

A service has two port numbers:

Documentation on the concept of a Service

Note: A Service can map any incoming port to a targetPort. By default and for convenience, the targetPort is set to the same value as the port field.