Skip to content

etc-binstack/kubernetes-cluster-bootstrap

Repository files navigation

K8s Bootstrap (Production-Ready)

Cloud-agnostic Kubernetes cluster bootstrap using kubeadm.

Directory

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

Features

  • Single-node & multi-node support
  • Auto-update .env with join command - Control plane installation automatically updates the .env file with the worker join command
  • Auto SSH worker join
  • Terraform AWS provisioning
  • Modular scripts
  • .env driven config

Usage

1. Configure

Edit .env based on .env.example

2. Run Control Plane

sudo bash k8s_precheck_installation.sh
sudo bash k8s_installation.sh

After installation completes:

  • The join command is automatically saved to join.sh and .env
  • A backup of .env is created as .env.backup.<timestamp>
  • The JOIN_COMMAND field in .env is populated with the actual join token

3. Add Workers

Option A: Automated (using add_nodes.sh)

# The .env file already contains the join command
bash scripts/add_nodes.sh

Option 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.sh

4. Cleanup & Reinstall

To completely uninstall and cleanup the cluster:

Standard cleanup (preserves config files):

sudo bash k8s_installation.sh cleanup

Full cleanup (removes everything):

# Edit .env and set CLEANUP_FULL=true, or export it:
export CLEANUP_FULL=true
sudo bash k8s_installation.sh cleanup

What 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.sh

Terraform (AWS)

cd terraform/aws
terraform init
terraform apply

About

Cloud-agnostic Kubernetes cluster bootstrap using kubeadm, Terraform & automation

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors