Welcome! This repository (fabriziosalmi/k8s) hosts a suite of Bash scripts meticulously crafted to simplify the setup, management, and monitoring of a single-node Kubernetes cluster. Ideal for homelab enthusiasts, testing environments, or anyone looking to quickly bootstrap a K8s instance.
Warning
You will have K8s up & running in less than 2 minutes! π
Satisfy requirements:
- Ubuntu 24
git
git clone https://github.com/fabriziosalmi/k8s
cd k8s
chmod +x install.sh
./install.shThese scripts aim to automate common, often repetitive, tasks involved in running a Kubernetes cluster and self-hosted applications:
- π
install.sh: Your starting point for a full setup! Automates the creation of a Kubernetesv1.29.0cluster (configurable) on a single Debian/Ubuntu node usingkubeadm. Handles prerequisites, container runtime (containerd), core components, networking (Calico), and optional extras like the Kubernetes Dashboard and a Caddy example. - π
switch.sh: A simple utility to control an existingkubeadm-based cluster. Use it to quicklystart(initialize if needed, or start services),stop(stop Kubelet/containerd),destroy(runkubeadm resetsafely), or check thestatusof your single-node cluster. Assumes core components are already installed. - βοΈ
manage.sh: An interactive application manager. Deploy or uninstall a curated list of popular self-hosted applications (Portainer, Nextcloud, Gitea, etc.) with basichostPathpersistence. Perfect for quick demos or simple single-node setups. - π
monitor.sh: A command-line dashboard providing a real-time health check and status overview of your cluster. See node status, resource usage (requires Metrics Server), control plane health, core addons, application summaries, and recent events at a glance.
Before diving in, ensure your environment meets these requirements:
- π§ Operating System: Debian or Ubuntu-based Linux distribution (tested on Ubuntu). Scripts use
apt-get,systemctl, etc. - π» Architecture: Primarily designed for
amd64. Manifests (like Calico ininstall.sh) might need adjustment for other architectures (e.g., ARM). - π Root Access:
install.shandswitch.shmust be run viasudoas they modify system services, packages, and configurations.manage.shneeds permissions to create directories under/srv/k8s-apps-data(default). Run as root (sudo) or adjust permissions on this path beforehand.
- π Internet Connection: Required by
install.shfor downloading packages and manifests.switch.shmight need it indirectly ifkubeadm initruns. - πͺ System Resources: Adequate CPU (2+ cores recommended), RAM (4GB+ recommended), and disk space for Kubernetes and your desired applications.
- π Bash: Version 4 or later (uses
mapfile/readarrayin some scripts). Check withbash --version. - π οΈ Required Tools:
- Standard GNU/Linux utilities:
curl,gpg,awk,sed,grep,sort,head,tail,wc,cut,printf,date,id,tee,modprobe,sysctl,systemctl,dpkg-query,apt-get,apt-mark,hostname,swapoff. jq: Highly recommended for reliable JSON parsing (install.sh,monitor.sh). Scripts have fallbacks butjqis preferred. Install viasudo apt-get update && sudo apt-get install -y jq.
- Standard GNU/Linux utilities:
- βΈοΈ Kubernetes Components:
- For
install.sh: It handles the installation ofkubeadm,kubelet,kubectl, andcontainerd. - For
switch.sh,manage.sh,monitor.sh: Assumekubectlis installed and configured (~/.kube/configorKUBECONFIGenv var) to connect to your cluster.switch.shalso requireskubeadm,kubelet, andcontainerd(or another runtime) to be present on the system for itsstart/stop/destroyactions. Verify withkubectl cluster-info.
- For
- (Optional) Metrics Server: Needed by
monitor.shto show Node Resource Usage. If not detected,monitor.shwill provide installation instructions.
This script bootstraps your single-node Kubernetes cluster from scratch.
Key Features:
- β System checks and preparation (swap, kernel modules, sysctl).
- π¦ Installs
containerdruntime. - βοΈ Installs specific, configurable versions of
kubelet,kubeadm,kubectl. - π Detects existing installations and offers safe options (reset, modify, exit).
- βΈοΈ Initializes the cluster via
kubeadm init. - π Configures
kubectlaccess for root and provides instructions for regular users. - π Installs Calico CNI for cluster networking.
- π― Untaints the control-plane node for workload scheduling (single-node focus).
- (Optional) Installs Kubernetes Dashboard & Caddy example.
- (Optional) Creates Dashboard admin user & provides access token.
- (Optional) Configures NodePort access for Dashboard/Caddy.
Configuration (install.sh Top Section):
| Variable | Default | Description |
|---|---|---|
K8S_VERSION |
1.29.0 |
Kubernetes version to install. |
CALICO_VERSION |
v3.27.2 |
Calico CNI version to install. |
DASHBOARD_VERSION |
v2.7.0 |
Kubernetes Dashboard version. |
INSTALL_DASHBOARD |
true |
Set to false to skip Dashboard installation. |
INSTALL_CADDY |
true |
Set to false to skip the Caddy example deployment. |
DASHBOARD_SERVICE_TYPE |
NodePort |
Set to ClusterIP to only expose Dashboard within the cluster (use kubectl proxy). |
Usage:
# 1. Make the script executable
chmod +x install.sh
# 2. Run as root
sudo ./install.shImportant
Read the prompts carefully, especially if an existing installation is detected. The reset option is DESTRUCTIVE to existing cluster configurations on the node. Review the script code before execution.
A streamlined utility for managing the lifecycle of your kubeadm-based single-node cluster. Assumes necessary components (kubeadm, kubelet, containerd, kubectl) are already installed (e.g., by install.sh or manually).
Key Features:
βΆοΈ start: Checks runtime & config. Initializes the cluster viakubeadm initif needed (runs pre-flight checks, untaints node). Startskubeletif configured but stopped.- βΉοΈ
stop: Stops thekubeletservice. Optionally stops thecontainerdservice as well. Does not remove configuration. - π₯
destroy: Runskubeadm reset --forceafter confirmation. Attempts to clean up common Kubernetes/CNI directories and restore swap settings in/etc/fstab. USE WITH EXTREME CAUTION. - βΉοΈ
status: Provides a quick overview of the runtime status, initialization state, Kubelet service status, and API server reachability (including node and CoreDNS checks if possible). - π‘οΈ Includes safety prompts for destructive actions.
- π Logs
kubeadm initandkubeadm resetoutput to files (kubeadm-init.log,kubeadm-reset.log).
Usage:
# 1. Make the script executable
chmod +x switch.sh
# 2. Run as root with the desired action
sudo ./switch.sh start
sudo ./switch.sh stop
sudo ./switch.sh status
sudo ./switch.sh destroy # <-- Be careful!Deploy and manage common self-hosted applications interactively.
Key Features:
- β¨ Interactive Install/Uninstall menu.
- π Manages apps like: Portainer, Nextcloud, Gitea, Vaultwarden, Uptime Kuma, Jellyfin, Home Assistant, File Browser.
- π¦ Creates necessary Kubernetes resources (Namespace, Deployment, Service, PV, PVC).
- π Provides NodePort access URLs upon successful installation.
- ποΈ Uninstall mode detects managed apps and allows selective removal.
- β Prompts for confirmation before deleting K8s resources and host data.
Warning
This script utilizes hostPath PersistentVolumes by default, storing data directly on the node's filesystem (typically under /srv/k8s-apps-data/<namespace>/).
- π¨ INSECURE: Permissions can be problematic, and data is not isolated.
- π NODE LOCK-IN: Data is tied to this specific node and won't migrate.
- π₯ NOT FOR PRODUCTION: Lacks features of proper storage solutions (snapshots, dynamic provisioning, etc.).
This approach is chosen for simplicity in a single-node homelab/testing setup ONLY. For anything more serious, implement a proper StorageClass (e.g., local-path-provisioner, NFS, Ceph, cloud provider storage).
Configuration (manage.sh Top Section):
HOST_DATA_BASE_DIR: Change the base path on the host node where application data directories will be created. Default:/srv/k8s-apps-data.
Usage:
- Ensure
kubectlis configured and can connect to your cluster. - Ensure the user running the script has write permissions to
HOST_DATA_BASE_DIRor run the script withsudo.
# 1. Make the script executable
chmod +x manage.sh
# 2. Run the script
# If HOST_DATA_BASE_DIR requires root:
sudo ./manage.sh
# Otherwise:
./manage.shFollow the on-screen menus. Be extremely careful during the uninstall process, especially when asked about deleting host data, as this action is irreversible.
Get a quick, comprehensive status overview of your cluster directly in the terminal.
Key Features:
- βΉοΈ Cluster Info: API endpoint, K8s server version.
- π» Node Status: Detailed list including readiness, roles, IPs, OS, Kubelet version.
- (Optional) π Resource Usage: Node CPU & Memory utilization summary (requires Metrics Server).
- β€οΈ Control Plane Health: Checks crucial health endpoints (
/readyz,/healthz). - π Core Addons: Status checks for CoreDNS and Calico.
- π¦ Application Overview: Pod counts (Running, Pending, Failed, Succeeded) and Deployment readiness per non-system namespace.
β οΈ Recent Events: Lists the latest Warning/Error events cluster-wide.- π¨ Color-coded output for quick identification of potential issues.
Configuration (monitor.sh Top Section):
EXCLUDE_NAMESPACES: An array of namespaces (e.g.,"kube-system","calico-system") to hide from the "Application Namespace Overview" section. Add any other system/infra namespaces here.
Usage:
- Ensure
kubectlis configured and can connect to your cluster.
# 1. Make the script executable
chmod +x monitor.sh
# 2. Run the script
./monitor.shThese scripts are powerful tools provided as-is for educational and homelab purposes. They modify system configurations, manage packages, interact with Kubernetes, and potentially delete data.
- π REVIEW THE CODE: Understand what each script does before running it.
β οΈ USE WITH CAUTION: Especially destructive options likekubeadm reset(install.sh,switch.sh) or data deletion during uninstalls (manage.sh).- πΎ BACKUP: Always back up critical data before performing major operations.
- π« NOT PRODUCTION-READY: The storage approach in
manage.sh(hostPath) is unsuitable for production. - β NO WARRANTY: The author provides no guarantees and is not responsible for any damage or data loss resulting from the use of these scripts.
- Add more applications to
manage.sh. - Integrate
local-path-provisioneras an optional, more robust storage solution ininstall.shandmanage.sh. - Support for other CNIs (e.g., Flannel, Cilium) in
install.sh. - Parameterize more options via command-line arguments instead of editing scripts.
- Improve error handling and reporting across all scripts.
- Add basic backup/restore helpers to
manage.sh.
Contributions, suggestions, and bug reports are welcome! Please feel free to open an Issue or Pull Request on the GitHub repository.
This project is licensed under the MIT License - see the LICENSE file for details (assuming you add an MIT license file).