Kubernetes Basics
Learn Kubernetes container orchestration from the ground up. Understand pods, deployments, services, and how to manage containerized applications at scale.
What is Kubernetes?
Kubernetes (often abbreviated as K8s) is an open-source container orchestration platform designed to automate the deployment, scaling, and management of containerized applications. Originally developed by Google, it is now maintained by the Cloud Native Computing Foundation (CNCF).
Kubernetes provides a framework to run distributed systems resiliently. It takes care of scaling and failover for your application, provides deployment patterns, and more.
Why Use Kubernetes?
- Service Discovery & Load Balancing - Kubernetes can expose containers using DNS or IP addresses and load balance traffic
- Storage Orchestration - Automatically mount storage systems of your choice
- Automated Rollouts & Rollbacks - Deploy changes gradually and rollback if something goes wrong
- Self-Healing - Restarts failed containers, replaces and reschedules containers
- Secret & Configuration Management - Deploy and update secrets and configuration without rebuilding images
Kubernetes Architecture
Control Plane Components
- kube-apiserver - The API server that exposes the Kubernetes API
- etcd - Consistent and highly-available key-value store for cluster data
- kube-scheduler - Watches for newly created Pods and selects nodes for them to run on
- kube-controller-manager - Runs controller processes
Node Components
- kubelet - An agent that runs on each node, ensuring containers are running in a Pod
- kube-proxy - Network proxy that maintains network rules on nodes
- Container Runtime - Software responsible for running containers (Docker, containerd, CRI-O)
Key Kubernetes Objects
- đˇ Pod - Smallest deployable unit, contains one or more containers
- đˇ Deployment - Manages Pod replicas and updates
- đˇ Service - Exposes Pods to network traffic
- đˇ ConfigMap - Stores configuration data as key-value pairs
- đˇ Secret - Stores sensitive data like passwords and tokens
- đˇ Namespace - Virtual clusters for resource isolation
# Get cluster info
kubectl cluster-info
# List all nodes
kubectl get nodes
# List all pods in default namespace
kubectl get pods
# List all pods in all namespaces
kubectl get pods --all-namespaces
# Describe a pod
kubectl describe pod <pod-name>
# View pod logs
kubectl logs <pod-name>
# Execute command in a pod
kubectl exec -it <pod-name> -- /bin/bash
# Apply a configuration
kubectl apply -f deployment.yaml
# Delete resources
kubectl delete -f deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.21
ports:
- containerPort: 80
resources:
limits:
memory: "128Mi"
cpu: "500m"
requests:
memory: "64Mi"
cpu: "250m"
Test Your Knowledge
Answer these questions to check your understanding