Linux VPS

K3s kurulumu (hafif Kubernetes)

Sınırlı kaynaklarla konteynerleri orkestre etmek için HolyCloud VPS'inizde hafif bir K3s Kubernetes kümesi dağıtın.

~15 dk. okuma Gelişmiş #kubernetes#k3s#containers#docker

K3s, 2 ila 4 GB RAM'li bir HolyCloud Linux VPS için ideal olan hafif bir Kubernetes dağıtımıdır (CNCF). containerd'yi, isteğe bağlı Traefik ingress'i ve tek bir ikili dosyayı bir arada sunar — tam bir kubeadm kümesinin getirdiği ek yük olmadan.

Ön koşullar

  • Ubuntu 22.04/24.04 veya Debian 12 yüklü HolyCloud VPS, en az 2 GB RAM (üretimde 4 GB önerilir)
  • root veya sudo erişimi
  • Hizmetleri dışarıya açıyorsanız 6443 (API), 10250 (kubelet) portlarının ve 30000-32767 (NodePort) aralığının açık olması
  • Çözümlenebilir ana bilgisayar adı (hostname -f yalnızca localhost döndürmemelidir)

İpucu: bir orkestratör kurmadan önce bir HolyCloud anlık görüntüsü oluşturun. K3s, iptables/nftables kurallarını değiştirir ve systemd hizmetleri kurar.

Adım 1: sistemin hazırlanması

Sistemi güncelleyin ve swap'i devre dışı bırakın (Kubernetes için zorunludur):

sudo apt update && sudo apt upgrade -y
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

Çekirdek modüllerini kontrol edin:

sudo modprobe overlay
sudo modprobe br_netfilter
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

Ağ parametreleri:

cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF
sudo sysctl --system

Adım 2: K3s kurulumu (sunucu)

HolyCloud VPS'inizin birincil düğümünde:

curl -sfL https://get.k3s.io | sudo sh -s - server \
  --write-kubeconfig-mode 644 \
  --tls-san $(curl -s ifconfig.me) \
  --tls-san $(hostname -f)

Başlamasını bekleyin:

sudo systemctl status k3s --no-pager
sudo k3s kubectl get nodes

Root olmayan bir kullanıcı için kubeconfig:

mkdir -p ~/.kube
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
sudo chown $USER:$USER ~/.kube/config
export KUBECONFIG=~/.kube/config
kubectl get pods -A

Adım 3: bir agent düğümü ekleme (isteğe bağlı)

İkinci bir HolyCloud VPS için belirteci sunucudan alın:

sudo cat /var/lib/rancher/k3s/server/node-token

Agent üzerinde (IP_SERVEUR ve TOKEN değerlerini değiştirin):

curl -sfL https://get.k3s.io | sudo K3S_URL=https://IP_SERVEUR:6443 \
  K3S_TOKEN=TOKEN sh -s - agent

Sunucudan doğrulayın:

kubectl get nodes -o wide

Adım 4: bir test uygulaması dağıtma

kubectl create deployment nginx-demo --image=nginx:alpine --replicas=2
kubectl expose deployment nginx-demo --port=80 --type=NodePort
kubectl get svc nginx-demo

NodePort değerini (ör. 31234) not edin ve kendi makinenizden test edin:

curl -I http://IP_PUBLIQUE_VPS_HOLYCLOUD:31234

Gerekirse bu portu UFW'de ve HolyCloud müşteri panelindeki güvenlik duvarında açın.

Adım 5: HTTPS ingress (Traefik dahildir)

K3s varsayılan olarak Traefik'i kurar. VPS'e yönlendirilmiş bir alan adı için örnek Ingress:

cat <<'EOF' | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: demo-ingress
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  tls:
  - hosts: [www.example.com]
    secretName: demo-tls
  rules:
  - host: www.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx-demo
            port:
              number: 80
EOF

Üretim için cert-manager kurun veya TLS'i aynı VPS üzerindeki Nginx ile kümenin önünde sonlandırın.

Bakım ve kaldırma

K3s'i güncelleme:

curl -sfL https://get.k3s.io | sudo sh -s - server

Tümüyle kaldırma:

sudo /usr/local/bin/k3s-uninstall.sh
# On an agent:
# sudo /usr/local/bin/k3s-agent-uninstall.sh

Doğrulama

kubectl cluster-info
kubectl get nodes
kubectl get pods -A
sudo journalctl -u k3s -n 50 --no-pager

Yardıma mı ihtiyacınız var?

  • Pod Pending durumunda: yetersiz RAM — VPS paketini yükseltin veya replika sayısını azaltın
  • API'ye erişilemiyor: 6443 portu, VPS'in genel IP'siyle --tls-san
  • Docker ile çakışma: K3s containerd kullanır; ileri düzey yapılandırma olmadan aynı düğümde iki çalışma zamanı bulundurmaktan kaçının
  • HolyCloud desteği: kubectl get nodes, free -h, sudo systemctl status k3s