A comprehensive set of scripts for managing Kubernetes clusters on Ubuntu systems, including installation, configuration, and cleanup operations.
- Overview
- Prerequisites
- Installation Guide
- Cleanup Guide
- Post-Installation Configuration
- Troubleshooting
- Support
This repository provides two main scripts:
setup-k8s.sh
: For installing and configuring Kubernetes nodescleanup-k8s.sh
: For safely removing Kubernetes components from nodes
Blog and additional information: https://www.munenick.me/blog/k8s-setup-script
- Ubuntu operating system (tested on Ubuntu 22.04 LTS)
- 2 CPUs or more
- 2GB of RAM per machine
- Full network connectivity between cluster machines
- Root privileges or sudo access
- Internet connectivity
- Open required ports for Kubernetes communication
Download and run the installation script:
curl -fsSL https://raw.github.com/MuNeNICK/setup-k8s/main/hack/setup-k8s.sh | sudo bash -s -- [options]
Manual download and inspection:
curl -fsSL https://raw.github.com/MuNeNICK/setup-k8s/main/hack/setup-k8s.sh -o setup-k8s.sh
less setup-k8s.sh
chmod +x setup-k8s.sh
Basic setup:
curl -fsSL https://raw.github.com/MuNeNICK/setup-k8s/main/hack/setup-k8s.sh | sudo bash -s -- --node-type master
Advanced setup:
curl -fsSL https://raw.github.com/MuNeNICK/setup-k8s/main/hack/setup-k8s.sh | sudo bash -s -- \
--node-type master \
--kubernetes-version 1.29 \
--pod-network-cidr 192.168.0.0/16 \
--apiserver-advertise-address 192.168.1.10 \
--service-cidr 10.96.0.0/12
Obtain join information from master node:
# Run on master node
kubeadm token create --print-join-command
Join worker node:
curl -fsSL https://raw.github.com/MuNeNICK/setup-k8s/main/hack/setup-k8s.sh | sudo bash -s -- \
--node-type worker \
--join-token <token> \
--join-address <address> \
--discovery-token-hash <hash>
Option | Description | Example |
---|---|---|
--node-type | Type of node (master/worker) | --node-type master |
--kubernetes-version | Kubernetes version | --kubernetes-version 1.29 |
--pod-network-cidr | Pod network CIDR | --pod-network-cidr 192.168.0.0/16 |
--apiserver-advertise-address | API server address | --apiserver-advertise-address 192.168.1.10 |
--control-plane-endpoint | Control plane endpoint | --control-plane-endpoint cluster.example.com |
--service-cidr | Service CIDR | --service-cidr 10.96.0.0/12 |
--join-token | Worker join token | --join-token abcdef.1234567890abcdef |
--join-address | Master address | --join-address 192.168.1.10:6443 |
--discovery-token-hash | Discovery token hash | --discovery-token-hash sha256:abc... |
Execute the cleanup script:
curl -fsSL https://raw.github.com/MuNeNICK/setup-k8s/main/hack/cleanup-k8s.sh | sudo bash -s -- [options]
- Drain the node (run on master):
kubectl drain <worker-node-name> --ignore-daemonsets
kubectl delete node <worker-node-name>
- Run cleanup on worker:
curl -fsSL https://raw.github.com/MuNeNICK/setup-k8s/main/hack/cleanup-k8s.sh | sudo bash -s -- --node-type worker
Warning: This will destroy your entire cluster.
- Ensure all worker nodes are removed first
- Run cleanup:
curl -fsSL https://raw.github.com/MuNeNICK/setup-k8s/main/hack/cleanup-k8s.sh | sudo bash -s -- --node-type master
Option | Description | Example |
---|---|---|
--node-type | Type of node (master/worker) | --node-type master |
--force | Skip confirmation prompts | --force |
--preserve-cni | Keep CNI configurations | --preserve-cni |
--help | Show help message | --help |
Install a Container Network Interface (CNI) plugin:
# Example: Installing Calico
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
Remove control-plane taint for single-node clusters:
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
Check cluster status:
kubectl get nodes
kubectl get pods --all-namespaces
- Check kubelet logs:
journalctl -xeu kubelet
- Verify system requirements
- Confirm network connectivity
- Verify network connectivity
- Check token expiration (24-hour default)
- Confirm firewall settings
- Ensure proper node drainage
- Verify permissions
- Check system logs:
journalctl -xe
- Issues and feature requests: Open an issue in the repository
- Additional assistance: Contact the maintainer
- Documentation updates: Submit a pull request