Working with Clusters

1. Creating Local Cluster

ToolCommandBest For
kindkind create cluster --name devCI, multi-node testing
minikubeminikube start --driver=dockerBeginners, add-ons
k3dk3d cluster create dev --agents 2Lightweight k3s
Docker DesktopSettings → Kubernetes → EnableSingle-node dev

2. Connecting to Remote Cluster

ProviderCommand
EKSaws eks update-kubeconfig --name CLUSTER --region us-east-1
GKEgcloud container clusters get-credentials CLUSTER --zone Z
AKSaz aks get-credentials -g RG -n CLUSTER
Manualkubectl config set-cluster ... / set-credentials / set-context

3. Viewing Cluster Nodes

CommandOutput
kubectl get nodesList nodes + status
kubectl get nodes -o wideAdds IPs, OS, runtime
kubectl get nodes --show-labelsInclude labels
kubectl get nodes -l role=workerFilter by label

4. Describing Node Details

SectionContains
ConditionsReady, MemoryPressure, DiskPressure, PIDPressure
Capacity / AllocatableCPU, memory, ephemeral-storage, pods
System InfoOS, kernel, container runtime, kubelet
Allocated resourcesSum of pod requests/limits
Non-terminated PodsList of pods running on node
kubectl describe node ip-10-0-1-23

5. Labeling Nodes

CommandAction
kubectl label node N1 disktype=ssdAdd label
kubectl label node N1 disktype-Remove label
kubectl label node N1 disktype=hdd --overwriteUpdate

6. Tainting Nodes

EffectBehavior
NoScheduleNew pods without toleration not scheduled
PreferNoScheduleSoft version of NoSchedule
NoExecuteEvicts existing pods without toleration
kubectl taint nodes N1 gpu=true:NoSchedule
kubectl taint nodes N1 gpu-      # remove

7. Cordoning Nodes

CommandEffect
kubectl cordon NODEMark unschedulable; existing pods stay
SchedulingDisabledStatus shown by kubectl get nodes

8. Draining Nodes

FlagUse
--ignore-daemonsetsSkip DaemonSet pods
--delete-emptydir-dataAllow eviction with emptyDir
--forceEvict unmanaged pods
--grace-period=60Override pod terminationGracePeriodSeconds
--timeout=5mMax wait
kubectl drain ip-10-0-1-23 --ignore-daemonsets --delete-emptydir-data

9. Uncordoning Nodes

CommandEffect
kubectl uncordon NODERe-enable scheduling after maintenance

10. Checking Cluster Health

CheckCommand
API healthkubectl get --raw='/readyz?verbose'
Livenesskubectl get --raw='/livez?verbose'
Node Readykubectl get nodes
Control plane podskubectl get pods -n kube-system
Eventskubectl get events -A --sort-by=.lastTimestamp

11. Viewing API Resources

CommandOutput
kubectl api-resourcesList all resource types
kubectl api-resources --namespaced=trueNamespaced only
kubectl api-versionsList API groups/versions
kubectl explain pod.spec.containersField documentation

12. Managing Cluster Certificates

CommandAction
kubeadm certs check-expirationShow cert expiry dates
kubeadm certs renew allRenew control-plane certs
kubectl get csrPending CSRs
kubectl certificate approve NAMEApprove CSR
Warning: Certs auto-renew on kubeadm upgrade. Otherwise renew before 1-year expiry.