07. Kubernetes Basics
Kubernetes orchestrates containerized workloads across clusters of machines. The control plane manages cluster state while worker nodes run scheduled workloads. Understanding the core concepts—pods, nodes, namespaces, and the kubectl command-line interface—provides the foundation for production AI deployments.
The control plane components include the API server accepting cluster operations, etcd maintaining consistent state, the scheduler assigning pods to nodes, and the controller manager running reconciliation loops. Control plane high availability requires multiple instances with election-based leadership.
Nodes host pods. Each node runs kubelet, the Kubernetes agent communicating with the control plane, and kube-proxy, the network proxy maintaining service connectivity. Node status reports condition information including memory pressure, disk pressure, and network availability.
Namespaces provide scope for resource isolation. Multi-tenant clusters use namespaces for team separation, resource quotas, and network policies. Resources within namespaces reference each other by name; cross-namespace communication requires explicit naming.
# Cluster exploration commands
kubectl cluster-info # Control plane endpoint
kubectl get nodes # List worker nodes with status
kubectl describe node <node-name> # Detailed node information
kubectl api-resources # Available resource types
kubectl version --client # kubectl version
# Namespace operations
kubectl get namespaces # List namespaces
kubectl create namespace ai-inference # Create namespace
kubectl config set-context --current \
--namespace=ai-inference # Set default namespace
Pods represent the smallest schedulable unit. A pod contains one or more containers sharing network namespace, process space, and storage volumes. Pods receive unique cluster IP addresses and share thelocalhost interface for intra-pod communication.
The pod lifecycle includes pending while scheduling occurs, running while containers execute, and terminal states succeeded or failed. Pod conditions report Ready, PodScheduled, and Initialized states through the status.conditions field.
kubectl provides the primary interface for interacting with clusters. The verb-noun resource pattern—get pods, describe deployment, logs pod-name—mirrors the Kubernetes API structure. Tab completion accelerates command entry for common operations.
Context switching enables single kubectl installations to manage multiple clusters. kubeconfig files store cluster credentials and context definitions. The current-context determines which cluster receives commands.
Deploy a simple stateless web service to a local Kubernetes cluster (minikube, kind, or k3s). Create a deployment with the official nginx image, expose it through a NodePort service, verify accessibility, then clean up all resources. Document each command and its effect on cluster state.
# Create deployment
kubectl create deployment nginx \
--image=nginx:latest \
--port=80 \
--replicas=3
# Expose via NodePort
kubectl expose deployment nginx \
--type=NodePort \
--port=80
# Verify deployment
kubectl get all
kubectl get pods -o wide
# Access the service
curl http://localhost:<NODE_PORT>
# View logs
kubectl logs deployment/nginx --follow --tail=20
# Cleanup
kubectl delete deployment nginx
kubectl delete service nginx