Oke, langsung ke setup K3s multi-node (1 master + 1 worker) di Ubuntu 24.04. Saya buat simpel tapi tetap production-minded.

๐งฉ Topologi dan Spec Contoh
- Master (server):
192.168.10.10( OS ubuntu 24.04 lts , CPU 4 GB , RAM 4 GB) - Worker (agent):
192.168.10.11( OS ubuntu 24.04 lts , CPU 2 GB , RAM 2 GB)
Pastikan:
- Bisa saling ping
- Port penting terbuka:
6443(API server)8472/UDP(Flannel VXLAN default)
โ๏ธ 1. Setup di Master Node
Login ke VM master, lalu jalankan:
hostnamectl set-hostname master
curl -sfL https://get.k3s.io | sh -
Cek status:
sudo systemctl status k3s
Cek node:
sudo kubectl get nodes
๐ Ambil Token Join
Token ini nanti dipakai worker:
sudo cat /var/lib/rancher/k3s/server/node-token
Contoh hasil:
K10d4f...::server:abcd1234
โ๏ธ 2. Setup di Worker Node
Di VM worker, jalankan:
hostnamectl set-hostname worker1
curl -sfL https://get.k3s.io | K3S_URL=https://192.168.10.10:6443 K3S_TOKEN=<TOKEN_DARI_MASTER> sh -
Contoh real:
curl -sfL https://get.k3s.io | \
K3S_URL=https://192.168.10.10:6443 \
K3S_TOKEN=K10d4f... \
sh -
โ 3. Verifikasi dari Master
Balik ke master:
kubectl get nodes
Output normal:
NAME STATUS ROLES AGE VERSION
master Ready control-plane,master ...
worker1 Ready <none> ...
๐ 4. Test Deploy Pod
Buat file:
nano nginx-deploy.yaml
Isi dengan ini:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: nginx
ports:
- port: 80
targetPort: 80
nodePort: 30080
๐ 2. Deploy ke K3s
Jalankan:
kubectl apply -f nginx-deploy.yaml
๐ 3. Cek status deployment
kubectl get pods -o wide
kubectl get svc
๐ 4. Akses dari browser
Kalau node IP kamu misalnya:
http://192.168.10.10:30080
atau worker juga bisa kalau routing jalan.
๐ 5. Cek apakah pod jalan di node mana
kubectl get pods -o wide
Kamu akan lihat:
- Pod 1 di master
- Pod 1 di worker (kalau scheduling jalan normal)
๐ง Kalau mau test lebih โKubernetes bangetโ
Scale deployment:
kubectl scale deployment nginx-deployment --replicas=5
Delete deployment:
kubectl delete -f nginx-deploy.yaml
