Container Platform

Kubernetes (kubeadm)

Production-grade container orchestration cluster setup

🐧 Linux🍎 Mac🪟 Windows📋 Quick reference →
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

If you're on Kubernetes 1.27 or older

  • Ingress: networking.k8s.io/v1 is required — v1beta1 removed in 1.22+
  • Pod Security: PodSecurityPolicy removed in 1.25 — use Pod Security Admission (PSA) labels
  • HPA v2 autoscaling/v2 is stable — check API version in manifests

If you're on Kubernetes 1.28

  • Sidecar containers (1.29+) change init-container ordering — review sidecar docs before upgrade
  • Verify metrics-server and HPA after control plane bump

What is this?

Kubernetes manages containers across many servers, restarting them if they crash and scaling when busy.

📁

Config files for Kubernetes (kubeadm)

Where to create or edit the main configuration — paths below match the setup steps.

  • deployment.yaml

    Location: Git repo or kubectl apply path

    Deployments, Services, Ingress, ConfigMaps

  • ~/.kube/config

    Location: User home — kubeconfig

    Cluster API URL, credentials, and context

📥

Step 01

Install Kubernetes Cluster

(01)Disable Swap & Load Kernel Modules

Linux
1sudo swapoff -a
2sudo sed -i '/ swap / s/^/#/' /etc/fstab
3
4cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
5overlay
6br_netfilter
7EOF
8
9sudo modprobe overlay
10sudo modprobe br_netfilter
11
12cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
13net.bridge.bridge-nf-call-iptables = 1
14net.bridge.bridge-nf-call-ip6tables = 1
15net.ipv4.ip_forward = 1
16EOF
17sudo sysctl --system

(02)Install containerd

Linux
1sudo apt-get update
2sudo apt-get install -y containerd
3sudo mkdir -p /etc/containerd
4containerd config default | sudo tee /etc/containerd/config.toml
5sudo systemctl restart containerd
6sudo systemctl enable containerd

(03)Install kubeadm, kubelet, kubectl

Linux
1sudo apt-get install -y apt-transport-https ca-certificates curl gpg
2curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
3echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.32/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
4sudo apt-get update
5sudo apt-get install -y kubelet kubeadm kubectl
6sudo apt-mark hold kubelet kubeadm kubectl
7sudo systemctl enable --now kubelet

(04)Initialize Control Plane

Linux
1sudo kubeadm init --pod-network-cidr=10.244.0.0/16
2
3mkdir -p $HOME/.kube
4sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
5sudo chown $(id -u):$(id -g) $HOME/.kube/config
6
7# Install CNI (Flannel)
8kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
⚙️

Step 02

Configure Kubernetes Cluster

(01)Create namespaces and RBAC

Linux
1kubectl create namespace dev
2kubectl create namespace staging
3kubectl create serviceaccount dev-user -n dev
4kubectl create rolebinding dev-admin --clusterrole=admin --serviceaccount=dev:dev-user -n dev
5kubectl config set-context --current --namespace=dev

(02)Deploy application with Service

Linux
1kubectl create deployment nginx --image=nginx --replicas=3
2kubectl expose deployment nginx --port=80 --type=NodePort
3kubectl get pods,svc
4kubectl scale deployment nginx --replicas=5

(03)Install metrics-server and dashboard

Linux
1kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
2kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
3kubectl get pods -n kube-system

Step 03

Verify Cluster

(01)Check Nodes & Pods

Linux
1kubectl get nodes
2kubectl get pods -A
3kubectl cluster-info

Step 04

Manage Cluster

(01)Join Worker Node

Linux
1# Run on worker node (use token from kubeadm init output)
2sudo kubeadm join <control-plane-ip>:6443 --token <token> \
3 --discovery-token-ca-cert-hash sha256:<hash>

(02)Reset Cluster

Linux
1sudo kubeadm reset
2sudo rm -rf /etc/cni/net.d /var/lib/etcd /var/lib/kubelet
🔧

Step 05

Common Problems

#1ImagePullBackOff

Kubernetes can't download the container image.

Linux
1# Check pod events
2kubectl describe pod <pod-name>
3# For local images (minikube/kind):
4docker build -t myapp:local .
5minikube image load myapp:local
6# Set imagePullPolicy: IfNotPresent in deployment

#2CrashLoopBackOff

Linux
1kubectl logs <pod-name>
2kubectl logs <pod-name> --previous
3kubectl describe pod <pod-name>

📋Config templates

21 YAML templates for Kubernetes (kubeadm). Copy and deploy after setup.

21 ready-to-copy templates. Expand one, copy the YAML, then run the deploy commands.

deployment.yml

Deployment with resource requests/limits and local image

yaml
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 labels:
5 app: api-deploy
6 name: api-deploy
7spec:
8 replicas: 1
9 selector:
10 matchLabels:
11 app: api-deploy
12 template:
13 metadata:
14 labels:
15 app: api-deploy
16 spec:
17 containers:
18 - image: api:local
19 name: api
20 imagePullPolicy: IfNotPresent
21 ports:
22 - containerPort: 3000
23 resources:
24 limits:
25 memory: "512Mi"
26 cpu: "500m"
27 requests:
28 memory: "256Mi"
29 cpu: "250m"

services.yml

NodePort Service exposing the API on port 32000

yaml
1apiVersion: v1
2kind: Service
3metadata:
4 labels:
5 app: api-deploy
6 name: api-deploy-service
7spec:
8 type: NodePort
9 selector:
10 app: api-deploy
11 ports:
12 - port: 3000
13 protocol: TCP
14 targetPort: 3000
15 nodePort: 32000
📄

Step 01

Apply to Kubernetes

(01)Build image and load into cluster

Linux
1# Build local image
2docker build -t api:local .
3
4# For Minikube / Kind — load image into cluster
5minikube image load api:local
6# OR: kind load docker-image api:local

(02)Apply manifests

Linux
1kubectl apply -f deployment.yml
2kubectl apply -f services.yml
3kubectl get pods,svc
4curl http://localhost:32000 # or minikube service api-deploy-service