Opinionated bootstrap scripts to stand up a small RKE2 Kubernetes cluster and (optionally) install Rancher on top.
- Target: Homelabs, development, or personal clusters (quick setup, simple defaults)
- Supported OS Families:
- Debian/Ubuntu-like (Debian, Ubuntu) using
apt - RHEL-like (Red Hat Enterprise Linux, Rocky Linux, AlmaLinux, CentOS) using
dnf/yum
- Debian/Ubuntu-like (Debian, Ubuntu) using
- Scope: OS preparation, RKE2 server/agent setup, Rancher deployment, and node teardown.
To prevent OS command conflicts (such as package managers or firewall systems), the bootstrap scripts are cleanly separated into dedicated directories:
.
├── rhel/ # For RHEL, Rocky Linux, AlmaLinux, CentOS
│ ├── prepare.sh # Sets up chronyd, SELinux Permissive/Disabled, NetworkManager, swap, modules
│ ├── install_rke2.sh # Installs RKE2 (server/agent), symlinks kubectl/crictl, creates local-path dir
│ ├── get_token.sh # Retrieves cluster join token
│ ├── install_rancher.sh # Deploys Helm, cert-manager, local-path storage, and Rancher Server
│ ├── rke2-clean-node.sh # Official killall/uninstall + force-deletes persistent directories
│ └── check_health.sh # Configures local kubectl and performs cluster health checks
│
├── ubuntu/ # For Debian, Ubuntu
│ ├── prepare.sh # Sets up timesyncd, UFW disable, swap, modules
│ ├── install_rke2.sh # Installs RKE2 (server/agent), symlinks kubectl/crictl, creates local-path dir
│ ├── get_token.sh # Retrieves cluster join token
│ ├── install_rancher.sh # Deploys Helm, cert-manager, local-path storage, and Rancher Server
│ ├── rke2-clean-node.sh # Official killall/uninstall + force-deletes persistent directories
│ └── check_health.sh # Configures local kubectl and performs cluster health checks
│
├── README.md # This documentation
└── troubleshooting_ip_fix.md # Multi-NIC IP routing troubleshooting log and guide
- Permissions: Root or sudo privileges on all nodes.
- Port requirements:
- Open 6443/tcp (Kubernetes API) and 9345/tcp (RKE2 Supervisor) on the Server node.
- Open 443/tcp on the node running Rancher.
- Allow inner-cluster CNI communication (e.g., Canal uses vxlan port 8472/udp).
Run the OS preparation script on every node (both Server and Agent).
- For Ubuntu/Debian:
sudo bash ubuntu/prepare.sh
- For RHEL-based OS:
sudo bash rhel/prepare.sh
[!IMPORTANT] For RHEL-based systems, you MUST reboot the node after running the script (
sudo reboot). This is mandatory for SELinux disable rules and NetworkManager unmanaged interface settings to take full effect.
On the node chosen as the control-plane/Server:
- For Ubuntu/Debian:
sudo bash ubuntu/install_rke2.sh <NODE_IP> init
- For RHEL-based OS:
sudo bash rhel/install_rke2.sh <NODE_IP> init
- Note: The script automatically links
kubectlandcrictlto/usr/local/binand configurescrictlfor easy container management.
On the initialized Server node, print and copy the token:
- For Ubuntu/Debian:
sudo bash ubuntu/get_token.sh - For RHEL-based OS:
sudo bash rhel/get_token.sh
On each additional worker/Agent node:
- For Ubuntu/Debian:
sudo bash ubuntu/install_rke2.sh <NODE_IP> join <SERVER_IP> <TOKEN>
- For RHEL-based OS:
sudo bash rhel/install_rke2.sh <NODE_IP> join <SERVER_IP> <TOKEN>
On the Server node, check the status of your nodes:
export KUBECONFIG=/etc/rancher/rke2/rke2.yaml
kubectl get nodes -o wideRun this script from the Server node (or any machine configured with access to kubectl):
- For Ubuntu/Debian:
export KUBECONFIG=/etc/rancher/rke2/rke2.yaml sudo bash ubuntu/install_rancher.sh <NODE_IP>
- For RHEL-based OS:
export KUBECONFIG=/etc/rancher/rke2/rke2.yaml sudo bash rhel/install_rancher.sh <NODE_IP>
What it does:
- Installs Helm and adds the
rancher-latestrepository. - Deploys
cert-manager(version pinned tov1.14.5). - Reconfigures
local-path-provisionerstorage path mapping to/data/local-path. - Deploys stateless Rancher Server pointing to
<NODE_IP>.sslip.iowith bootstrap passwordadmin.
If you need to uninstall RKE2 and delete all cluster data, execute the clean-node script.
Caution
This will wipe all containers, configurations, and persistent volumes under /data!
# For Ubuntu
sudo bash ubuntu/rke2-clean-node.sh
# For RHEL
sudo bash rhel/rke2-clean-node.sh- Quyền hạn: Quyền Root hoặc Sudo trên tất cả các node.
- Yêu cầu về Cổng (Ports):
- Mở cổng 6443/tcp (Kubernetes API) và 9345/tcp (RKE2 Supervisor) trên Server node.
- Mở cổng 443/tcp trên node expose Rancher.
- Cho phép traffic nội bộ cụm (ví dụ Canal dùng cổng vxlan 8472/udp).
Chạy script chuẩn bị hệ thống trên từng node (cả Server và Agent).
- Với Ubuntu/Debian:
sudo bash ubuntu/prepare.sh
- Với các hệ điều hành nhân RHEL:
sudo bash rhel/prepare.sh
[!IMPORTANT] Với RHEL-based OS, bạn BẮT BUỘC phải khởi động lại máy (
sudo reboot) sau khi chạy script này để cấu hình tắt SELinux và nạp lại cấu hình bỏ qua card mạng ảo của NetworkManager có hiệu lực hoàn toàn.
Trên node được chọn làm control-plane:
- Với Ubuntu/Debian:
sudo bash ubuntu/install_rke2.sh <NODE_IP> init
- Với RHEL-based OS:
sudo bash rhel/install_rke2.sh <NODE_IP> init
- Lưu ý: Script tự động tạo liên kết động (symlink) đưa lệnh
kubectlvàcrictlra toàn hệ thống tại thư mục/usr/local/binvà cấu hình sẵn file socket củacrictl.
Trên node Server, lấy token:
- Với Ubuntu/Debian:
sudo bash ubuntu/get_token.sh - Với RHEL-based OS:
sudo bash rhel/get_token.sh
Trên các node Agent còn lại, chạy lệnh trỏ về IP của Server kèm Token:
- Với Ubuntu/Debian:
sudo bash ubuntu/install_rke2.sh <NODE_IP> join <SERVER_IP> <TOKEN>
- Với RHEL-based OS:
sudo bash rhel/install_rke2.sh <NODE_IP> join <SERVER_IP> <TOKEN>
Từ node Server, chạy lệnh kiểm tra trạng thái các node:
export KUBECONFIG=/etc/rancher/rke2/rke2.yaml
kubectl get nodes -o wideChạy script này từ node Server (hoặc bất kỳ máy nào cấu hình sẵn file KUBECONFIG trỏ về cụm):
- Với Ubuntu/Debian:
export KUBECONFIG=/etc/rancher/rke2/rke2.yaml sudo bash ubuntu/install_rancher.sh <NODE_IP>
- Với RHEL-based OS:
export KUBECONFIG=/etc/rancher/rke2/rke2.yaml sudo bash rhel/install_rancher.sh <NODE_IP>
Khi cần gỡ cài đặt RKE2 và xóa toàn bộ dữ liệu cụm để cài lại:
Caution
Thao tác này sẽ xóa sạch các container, cấu hình và dữ liệu Persistent Volumes lưu trong phân vùng /data!
# Cho Ubuntu/Debian
sudo bash ubuntu/rke2-clean-node.sh
# Cho RHEL-based
sudo bash rhel/rke2-clean-node.sh- Rancher Password: Rancher được bootstrap với mật khẩu mặc định là
admin. Thay đổi mật khẩu quản trị ngay lập tức trong lần đăng nhập đầu tiên. - Kubeconfig Mode: Để thuận tiện cho môi trường test/homelab, quyền truy cập tệp Kubeconfig (
/etc/rancher/rke2/rke2.yaml) được cấu hình mặc định là0644. Trong môi trường production, hãy siết chặt quyền (chmod 600) để bảo vệ cụm tránh truy cập trái phép.