# Ubuntu 安裝 kubectl 方法


# 方法一 下載來安裝

1
2
3
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl # 可執行權限
sudo mv kubectl /usr/local/bin # 放置到環境變數下

# 方法二 透過 apt

# 添加 GPG key 與添加來源

1
2
3
4
5
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

sudo apt-get update

# 安裝

1
sudo apt install kubectl

# 輸出 k3s Kube Config

1
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml