Cloud-agnostic Kubernetes cluster bootstrap using kubeadm.
k8s-bootstrap-prod/
├── .env # ✅ Environment configuration (validated & production-ready)
├── k8s_precheck_installation.sh # ✅ Pre-flight validation (already working perfectly)
├── k8s_installation.sh # ✅ Main orchestrator (minor tweak applied below)
├── lib/ # ✅ Modular function library (NOW COMPLETE)
│ ├── common.sh # ✅ Hostname utilities + logging + error handling + validation
│ ├── install.sh # ✅ Runtime & K8s tools installation (THIS WAS THE BLOCKER)
│ ├── kubeadm_config.sh # ✅ Dynamic kubeadm config generator
│ ├── kubeadm.sh # ✅ Cluster init & join logic
│ └── network.sh # ✅ CNI plugin installation
├── scripts/ # Automation helpers (ready for next step)
│ ├── add_nodes.sh # SSH-based worker addition (will work after control-plane)
│ └── nodes.txt # Worker node IP list
└── terraform/aws/ # Infrastructure provisioning (optional, already good)
└── main.tf # AWS EC2 instance template
- Single-node & multi-node support
- Auto-update
.envwith join command - Control plane installation automatically updates the.envfile with the worker join command - Auto SSH worker join
- Terraform AWS provisioning
- Modular scripts
- .env driven config
Edit .env based on .env.example
sudo bash k8s_precheck_installation.sh
sudo bash k8s_installation.shAfter installation completes:
- The join command is automatically saved to
join.shand.env - A backup of
.envis created as.env.backup.<timestamp> - The
JOIN_COMMANDfield in.envis populated with the actual join token
Option A: Automated (using add_nodes.sh)
# The .env file already contains the join command
bash scripts/add_nodes.shOption B: Manual
# On the control plane, check the join command
cat join.sh
# Or copy the .env file to worker nodes
scp .env user@worker-node:/opt/kubernetes-cluster-bootstrap/
# Then on worker node:
sudo bash k8s_installation.shTo completely uninstall and cleanup the cluster:
Standard cleanup (preserves config files):
sudo bash k8s_installation.sh cleanupFull cleanup (removes everything):
# Edit .env and set CLEANUP_FULL=true, or export it:
export CLEANUP_FULL=true
sudo bash k8s_installation.sh cleanupWhat gets cleaned:
- ✅ Drains and removes node from cluster
- ✅ Runs
kubeadm reset - ✅ Removes CNI network interfaces (Calico, Flannel, etc.)
- ✅ Cleans up
/etc/cni/net.d - ✅ Flushes iptables and IPVS rules
- ✅ Restarts container runtime
- ✅ (If
CLEANUP_FULL=true) Removes/etc/kubernetes,/var/lib/kubelet,/var/lib/etcd, kubeconfig files
Interactive cleanup options:
After cleanup completes, you'll be prompted with:
What would you like to do next?
1) Keep binaries for reinstallation (recommended)
2) Remove all Kubernetes binaries completely
3) Exit without changes
- Option 1 (Recommended): Keeps kubectl, kubeadm, kubelet for quick reinstallation
- Option 2: Completely removes all Kubernetes packages and optionally the APT repository
- Option 3: Exit without making changes
After cleanup, you can reinstall:
sudo bash k8s_installation.shcd terraform/aws
terraform init
terraform apply