Lab 05 - First look at the cluster
Lab 05 - First look at the cluster
Goal: see what the cluster is made of, and the difference between imperative and declarative. Cheat sheet: kubectl
# 1 - where am I connected, and as whom?
kubectl cluster-info
kubectl config get-contexts
kubectl config view --minify | grep server
Get into the habit of config get-contexts before anything destructive. Most
production accidents are a command typed against the right object in the wrong
cluster.
# 2 - the machines
kubectl get nodes -o wide
kubectl describe node control01 | head -40
kubectl describe node worker01 | grep -A6 'Allocated resources'
In describe node, three blocks matter: Conditions (is it healthy?),
Taints (what refuses to run here?) and Allocated resources (how full is
it?). Note that allocation is counted from Pod requests, not actual usage.
# 3 - what does the control plane run for itself?
kubectl get pods -n kube-system -o wide
You should recognise most of it from the architecture diagram: the API server, etcd, the scheduler, the controller manager, CoreDNS, and one CNI Pod per node.
Imperative
# 4 - an action, executed once
kubectl run web01 --image nginx:1.27
kubectl get pods -o wide
kubectl run web01 --image nginx:1.27 # error: already exists - not idempotent
kubectl delete pod web01
Declarative
# 5 - generate the manifest instead of writing it
cd ~
kubectl run web01 --image nginx:1.27 --dry-run=client -o yaml > web01.yaml
cat web01.yaml
--dry-run=client builds the object locally and prints it instead of sending
it. This is the fastest route to a correct manifest - generate, then edit.
# 6 - apply it twice
kubectl apply -f web01.yaml
kubectl apply -f web01.yaml # "unchanged" - idempotent
kubectl get pod web01
The second apply is a no-op because the desired state already matches. This is
what makes apply safe in a pipeline and run unsuitable for one.
# 7 - change the file, apply again
sed -i 's/nginx:1.27/nginx:1.28/' web01.yaml
kubectl apply -f web01.yaml
kubectl get pod web01 -o jsonpath='{.spec.containers[0].image}{"\n"}'
Clean up
# 8 - delete with the same file you created it from
kubectl delete -f web01.yaml