Advertisement
Intermediate Time: 3–4 weeks IT & Networking

Docker and Kubernetes Cluster Setup

Deploy a production Kubernetes cluster using kubeadm, configure persistent storage, ingress, monitoring, and GitOps with ArgoCD.

DockerKubernetesK8sContainerDevOpsMicroservices
DifficultyIntermediate
Duration3–4 weeks
Components10 items
Steps6 steps

Introduction

Deploy a production Kubernetes cluster using kubeadm, configure persistent storage, ingress, monitoring, and GitOps with ArgoCD. This comprehensive guide covers everything from design through implementation, testing, and deployment.

Theory & Background

Control Plane (master): API Server (central REST API for all K8s operations), etcd (distributed key-value store for all cluster state), Scheduler (assigns pods to nodes), Controller Manager (enforces desired state). Worker Nodes: kubelet (ensures containers run as specified), kube-proxy (implements network rules for Services), Container Runtime (containerd or CRI-O). Minimum for production: 3 control plane nodes (HA) + 3+ worker nodes. For learning: 1 master + 2 workers.

Advertisement

Components & Requirements

10 components required for this project.

#ComponentPurposeQty
1Ubuntu 22.04 VMs (3–5 nodes)1 master + 2–4 worker nodesx3–5
2kubeadmKubernetes cluster bootstrap toolx1
3Flannel or Calico CNIPod networking (Container Network Interface)x1
4MetalLBLoadBalancer for bare-metal Kubernetesx1
5NGINX Ingress ControllerHTTP/HTTPS routing to servicesx1
6cert-managerAutomatic TLS certificate provisioningx1
7Helm 3Kubernetes application packagingx1
8ArgoCDGitOps continuous deploymentx1
9Prometheus + Grafana StackCluster monitoring and alertingx1
10Longhorn (storage)Distributed block storage for PersistentVolumesx1

Step-by-Step Implementation

Follow these 6 steps carefully.

1
Kubernetes Architecture Overview

Control Plane (master): API Server (central REST API for all K8s operations), etcd (distributed key-value store for all cluster state), Scheduler (assigns pods to nodes), Controller Manager (enforces desired state). Worker Nodes: kubelet (ensures containers run as specified), kube-proxy (implements network rules for Services), Container Runtime (containerd or CRI-O). Minimum for production: 3 control plane nodes (HA) + 3+ worker nodes. For learning: 1 master + 2 workers.

2
Cluster Bootstrap with kubeadm

On all nodes: disable swap (Kubernetes requirement), install containerd runtime, install kubeadm/kubelet/kubectl. On master: kubeadm init --pod-network-cidr=10.244.0.0/16 (for Flannel). Copy kubeconfig: mkdir ~/.kube && cp /etc/kubernetes/admin.conf ~/.kube/config. Install CNI: kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml. On workers: kubeadm join master_ip:6443 --token TOKEN --discovery-token-ca-cert-hash HASH (from master init output).

3
Persistent Storage with Longhorn

Longhorn provides distributed block storage: each PersistentVolume is replicated across 3 worker nodes. Install via Helm: helm install longhorn longhorn/longhorn --namespace longhorn-system. Create StorageClass (set as default): class.longhorn.io. Create PVC (PersistentVolumeClaim) of 10Gi. Longhorn automatically provisions the PV, replicates data. Access mode: ReadWriteOnce (one pod) or ReadWriteMany (multiple pods simultaneously). Monitor via Longhorn UI.

4
Ingress and TLS Setup

MetalLB provides LoadBalancer IPs in bare-metal environments (cloud K8s handles this automatically). Configure L2 mode with IP range from your LAN. Install NGINX Ingress Controller: helm install ingress-nginx ingress-nginx/ingress-nginx. Install cert-manager for automatic TLS: helm install cert-manager cert-manager/cert-manager --set installCRDs=true. Create ClusterIssuer using Let's Encrypt. Create Ingress resource: routes catb.in → catb-service:80, with TLS annotation for automatic certificate.

5
GitOps with ArgoCD

GitOps: Kubernetes manifests stored in Git. ArgoCD watches Git repo, syncs cluster state to match Git. Install ArgoCD: kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml. Create Application resource: sourcePath=k8s/, destinationNamespace=production. On every Git push (via CI/CD): ArgoCD detects change, auto-syncs new manifests to cluster. Audit trail: all changes tracked in Git history with author, timestamp, and diff.

6
Monitoring with Prometheus Stack

Install kube-prometheus-stack: helm install monitoring prometheus-community/kube-prometheus-stack. Includes: Prometheus (metrics), Grafana (dashboards), AlertManager (notifications), node-exporter (hardware metrics), kube-state-metrics (K8s object metrics). Access Grafana: kubectl port-forward svc/monitoring-grafana 3000:80. Pre-built dashboards: cluster capacity, pod restart rates, network traffic, storage usage, API server request rate. Configure PagerDuty/Slack alerts for critical events.

Code & Implementation

Core code for deployment.yaml:

deployment.yaml YAML
# Example CATB.in application deployment apiVersion: apps/v1 kind: Deployment metadata:   name: catb-web   namespace: production spec:   replicas: 3   selector:     matchLabels: {app: catb-web}   template:     metadata:       labels: {app: catb-web}     spec:       containers:       - name: catb-web         image: registry.catb.in/catb-web:v1.2.3         ports: [{containerPort: 3000}]         resources:           requests: {cpu: "100m", memory: "128Mi"}           limits:   {cpu: "500m", memory: "512Mi"}         readinessProbe:           httpGet: {path: /health, port: 3000}           initialDelaySeconds: 10           periodSeconds: 5         livenessProbe:           httpGet: {path: /health, port: 3000}           initialDelaySeconds: 30           periodSeconds: 10 --- apiVersion: v1 kind: Service metadata:   name: catb-service   namespace: production spec:   selector: {app: catb-web}   ports: [{port: 80, targetPort: 3000}] --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata:   name: catb-ingress   namespace: production   annotations:     cert-manager.io/cluster-issuer: "letsencrypt-prod"     nginx.ingress.kubernetes.io/ssl-redirect: "true" spec:   tls:   - hosts: [catb.in]     secretName: catb-tls   rules:   - host: catb.in     http:       paths:       - path: /         pathType: Prefix         backend:           service: {name: catb-service, port: {number: 80}}

Testing & Troubleshooting

Test Docker and Kubernetes Cluster Setup by verifying each subsystem individually before full integration.

!
Troubleshooting Tips

Verify power voltages, check ground connections, use serial monitor for debug.

Real-World Applications

*Microservices production deployment
*CI/CD pipeline infrastructure
*Multi-tenant SaaS application hosting
*Machine learning model serving
*Data processing pipeline orchestration
*Development environment standardization
*High-availability web application hosting
*Edge computing workload management

Extensions & Next Steps

  • Implement auto-scaling with HPA and VPA
  • Set up multi-cluster federation for global deployment
  • Implement network policies for micro-segmentation
  • Build a service mesh with Istio for observability
  • Add OPA Gatekeeper for policy-as-code admission control

Interactive Playground

Coming Soon

An interactive simulator will be available here — simulate circuits and run code in-browser without hardware.

Frequently Asked Questions

When should I use Docker Compose vs Kubernetes?
Docker Compose: ideal for local development, small single-server deployments, simple multi-container applications with < 5 services, and teams without dedicated DevOps. Simple YAML defines services, volumes, networks on one machine. Kubernetes: use when you need: high availability (multiple replicas across servers), automatic failover (pod restarts, node failures), horizontal scaling (more pods under load), rolling deployments, secret management at scale, or when running 10+ microservices. Rule of thumb: start with Docker Compose, migrate to Kubernetes when you need it, not before.
What is a Kubernetes Pod vs Deployment vs Service?
Pod: the smallest deployable unit — one or more co-located containers sharing network namespace and storage. Direct pod creation is ephemeral — dies if node fails. Deployment: manages a set of identical Pod replicas. Ensures desired replica count (restarts crashed pods, replaces pods on node failure). Handles rolling updates and rollbacks. Service: stable network endpoint for accessing Pods (pods have dynamic IPs). Types: ClusterIP (internal), NodePort (external via node port), LoadBalancer (cloud LB), ExternalName (DNS alias). Think: Pod = one container group, Deployment = many pods, Service = how to reach them.
Advertisement