Kubernetes
Commands
Get information about all pods:
Get information about all pods, including information on their IP, Node, and Readiness status:
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
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:
- The internal port "Port"
- The service will direct network traffic to the "TargetPort", so a pod has to have a "NodePort" that matches the "TargetPort" of the service.
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.