Containerization
Kubernetes Cluster Setup & Deployment
Production-ready Kubernetes cluster for scaling applications to handle 1000 concurrent users with deployment orchestration.
What you'll learn
- Bootstrap a multi-node Kubernetes cluster with kubeadm
- Configure CNI networking with Flannel or Calico
- Deploy a sample application and expose it via LoadBalancer
- Configure storage classes and persistent volumes
- Implement rolling updates and rollbacks
- Scale deployments to handle 1000+ concurrent users
Prerequisites & Planning
Plan your cluster topology before installation. A minimum production cluster needs one control plane node and two worker nodes.
Bash
1# Run on ALL nodes
2sudo swapoff -a
3sudo sed -i '/ swap / s/^/#/' /etc/fstab
4
5# Load kernel modules
6cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
7overlay
8br_netfilter
9EOF
10sudo modprobe overlay
11sudo modprobe br_netfilter
12
13# Configure sysctl for Kubernetes
14cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
15net.bridge.bridge-nf-call-iptables = 1
16net.bridge.bridge-nf-call-ip6tables = 1
17net.ipv4.ip_forward = 1
18EOF
19sudo sysctl --systemControl Plane Setup
Bash
1# On control-plane node only
2sudo kubeadm init \
3 --pod-network-cidr=10.244.0.0/16 \
4 --control-plane-endpoint="LOAD_BALANCER_IP:6443"
5
6# Copy kubeconfig
7mkdir -p $HOME/.kube
8sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config
9sudo chown $(id -u):$(id -g) $HOME/.kube/config
10
11# Save the join command output — needed for workers
12kubeadm token create --print-join-commandJoin Worker Nodes
Bash
1# On each worker node — paste the join command from kubeadm init output
2sudo kubeadm join CONTROL_PLANE_IP:6443 \
3 --token <token> \
4 --discovery-token-ca-cert-hash sha256:<hash>
5
6# Verify from control plane
7kubectl get nodesCNI Networking
Bash
1# Install Flannel
2kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
3
4# Verify all nodes become Ready
5kubectl get nodes --watchPersistent Storage
YAML
1# PersistentVolumeClaim example
2apiVersion: v1
3kind: PersistentVolumeClaim
4metadata:
5 name: postgres-pvc
6spec:
7 accessModes: [ReadWriteOnce]
8 storageClassName: standard
9 resources:
10 requests:
11 storage: 20GiDeploy & Scale
Bash
1# Deploy application
2kubectl apply -f deployment.yaml
3
4# Scale to handle load
5kubectl scale deployment api --replicas=10
6
7# Rolling update
8kubectl set image deployment/api api=ghcr.io/org/api:v2.0.0
9
10# Monitor rollout
11kubectl rollout status deployment/api
12
13# Rollback if needed
14kubectl rollout undo deployment/api