Ubuntu Server 22.04 LTS部署Kubernetes 1.26.0

關(guān)閉Swap

sudo swapoff -a
# 取消掛載swap分區(qū),在swap行首添加# 
例如 #/swap.img      none    swap    sw      0       0
sudo vim /etc/fstab

安裝Docker

# 更新安裝源列表
sudo apt-get update
# 安裝前提必須文件
sudo apt-get install ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# 添加docker源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
# 安裝dokcer和容器運(yùn)行時(shí)等
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# 運(yùn)行docker,并加入開(kāi)機(jī)啟動(dòng)
sudo systemctl enable --now docker
# 測(cè)試安裝是否成功,如果安裝成功會(huì)看到hello world輸出
sudo docker run hello-world

使用阿里鏡像源安裝Kubeadm

sudo apt-get install -y apt-transport-https

sudo curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - 

sudo cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF

sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo systemctl enable --now kubelet

安裝Kubernetes

生成并編輯containerd配置文件

containerd config default | sudo tee /etc/containerd/config.toml
# 使用阿里源替換不可訪問(wèn)的國(guó)外源
sudo sed -i 's/registry.k8s.io/registry.aliyuncs.com\/google_containers/g' /etc/containerd/config.toml

在config.toml的[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]條目下,將SystemdCgroup = false改為SystemdCgroup = true
注意,config.toml有多處SystemdCgroup配置,不要改錯(cuò)了位置。

sudo systemctl enable containerd
sudo systemctl restart containerd

使用Kubeadm部署Kubernetes

# 根據(jù)環(huán)境配置你的--pod-network-cidr的值,不能與已有的網(wǎng)絡(luò)重復(fù)
sudo kubeadm init --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.10.0.0/16

復(fù)制配置文件到當(dāng)前用戶(hù)目錄

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

安裝Calico

kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.5/manifests/tigera-operator.yaml
wget https://raw.githubusercontent.com/projectcalico/calico/v3.24.5/manifests/custom-resources.yaml
# 編輯custom-resources.yaml,確保cidr配置的值與之前--pod-network-cidr的值相同
kubectl create -f custom-resources.yaml

如果你無(wú)法訪問(wèn)以上兩個(gè)Github文件,可以從這里下載

查看結(jié)果

以下命令需要顯示所有的pod處于Running狀態(tài)

watch kubectl get -A pods

安裝Dashboard

如果只有一個(gè)節(jié)點(diǎn),那么安裝Dashboard前需要運(yùn)行以下命令

kubectl taint nodes --all node-role.kubernetes.io/control-plane-

開(kāi)始部署Dashboard

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

官方說(shuō)明文檔

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容