K3s คืออะไร?
K3s เป็น Kubernetes Distribution ที่ lightweight และ production-ready สร้างโดย Rancher Labs มีขนาดเล็กกว่า Kubernetes แบบปกติมาก (เพียง 40MB) ทำให้เหมาะสำหรับ Cloud VPS, Edge Computing หรือ IoT devices
K3s มาพร้อมกับ Traefik Load Balancer, Local Storage Provisioner และ Metric Server ตั้งแต่แรก ทำให้ติดตั้งใช้งานง่ายกว่า Kubernetes ที่ต้องติดตั้งเพิ่มเติมอีกมาก
เหตุใดจึงเลือก K3s บน Cloud VPS
- ประหยัดทรัพยากร: ใช้ CPU และ Memory น้อย เหมาะสำหรับ VPS ขนาดเล็ก
- ติดตั้งง่าย: ใช้คำสั่ง 1 บรรทัด ติดตั้งเสร็จใน 1-2 นาที
- ปกติใช้งาน: ถึงแม้เบา แต่ก็มีความสามารถเต็มที่ของ Kubernetes
- Built-in Tools: มี Load Balancer และ Storage อยู่แล้ว
- Perfect for Development: เหมาะสำหรับสภาพแวดล้อม dev, staging และ production ขนาดเล็ก
ข้อกำหนด: ก่อนติดตั้ง K3s
- Cloud VPS ขั้นต่ำ: 1 CPU, 512MB RAM (แนะนำ: 2 CPU, 2GB RAM)
- OS: Ubuntu 18.04 ขึ้นไป, CentOS 7 ขึ้นไป, หรือ Debian
- Network: Open ports 6443 (Kubernetes API)
- Sudo access ในการติดตั้ง
ขั้นตอนติดตั้ง K3s บน Cloud VPS
1. อัปเดต System Package
sudo apt update && sudo apt upgrade -y
2. ติดตั้ง K3s
curl -sfL https://get.k3s.io | sh -
รอสักครู่เพื่อให้ K3s ติดตั้งเสร็จสมบูรณ์
3. ตรวจสอบสถานะ K3s
sudo k3s kubectl get nodes
sudo k3s kubectl get pods --all-namespaces
4. ตั้งค่า kubectl (optional)
mkdir -p ~/.kube
sudo cat /etc/rancher/k3s/k3s.yaml > ~/.kube/config
chmod 600 ~/.kube/config
ตอนนี้คุณสามารถใช้ kubectl แทน sudo k3s kubectl
การตรวจสอบการติดตั้ง
kubectl version
kubectl get nodes
kubectl get pods --all-namespaces
Deploy แอปพลิเคชันตัวแรก
สร้าง file deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
spec:
replicas: 2
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: nginx:latest
ports:
- containerPort: 80
Deploy ด้วยคำสั่ง:
kubectl apply -f deployment.yaml
kubectl get pods
เปิดใช้งาน Port Forward
kubectl port-forward deployment/hello-world 8080:80 --address=0.0.0.0
ตอนนี้คุณสามารถเข้าถึง http://your-vps-ip:8080
คำสั่ง K3s ที่มีประโยชน์
# ดูสถานะของระบบ
kubectl cluster-info
# ดู Node status
kubectl get nodes -o wide
# ดู All Pods
kubectl get pods -A
# ดู Logs
kubectl logs pod-name -n namespace
# ลบ Pod
kubectl delete pod pod-name -n namespace
# Get Service
kubectl get svc -A
การสิ้นสุด K3s
# หากต้องการลบ K3s
sudo /usr/local/bin/k3s-uninstall.sh
ข้อเสีย K3s ที่ต้องทำความเข้าใจ
- ใช้ SQLite แทน etcd (ไม่เหมาะสำหรับ Multi-master high availability)
- เหมาะสำหรับ Single Node หรือ Small Cluster เท่านั้น
- ไม่มี Dashboard มาตรฐาน (ต้องติดตั้งเอง)
สรุป
K3s เป็นตัวเลือกที่ยอดเยี่ยมสำหรับการรัน Kubernetes บน Cloud VPS ด้วยความเบา รวดเร็ว และ production-ready Dot Enterprise มี Cloud VPS ที่เหมาะสำหรับรัน K3s ด้วยราคาที่ประหยัด
