當(dāng)前位置:首頁 > IT技術(shù) > Web編程 > 正文

【最全國(guó)內(nèi)安裝教程】通過minikube運(yùn)行單節(jié)點(diǎn)Kubernetes集群
2021-09-10 18:22:37

?

?

前言

minikube的方便不用我過多言語了吧,一些書上都是基于國(guó)外資源進(jìn)行安裝部署。通過在網(wǎng)上沖浪后,我整理出來了一份國(guó)內(nèi)安裝minikube的詳細(xì)過程

【最全國(guó)內(nèi)安裝教程】通過minikube運(yùn)行單節(jié)點(diǎn)Kubernetes集群_docker

從零開始安裝minikube

前提配置

添加阿里鏡像源,下載kubectl

sudo apt-get update
sudo apt-get install -y apt-transport-https, docker.io
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 kubectl

更換Docker鏡像下載源
通過阿里云控制臺(tái)配置Docker鏡像源(配置屬于自己的Docker鏡像源)
https://cr.console.aliyun.com/cn-shanghai/instances/mirrors
ps:也可以省略此步,將Docker鏡像源修改為https://registry.docker-cn.com即可
【最全國(guó)內(nèi)安裝教程】通過minikube運(yùn)行單節(jié)點(diǎn)Kubernetes集群_linux_02

修改/etc/docker/daemon.json

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
 "registry-mirrors": ["https://registry.docker-cn.com"]
 # 最好更換為自己設(shè)置鏡像源!
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

通過阿里云下載minikube

阿里云修改了官方的minikube,這更適用于國(guó)內(nèi)環(huán)境
https://github.com/AliyunContainerService/minikube/wiki
這個(gè)wiki會(huì)更新最新的minikube版本及下載方案

這里安裝的是v1.2.0

curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.2.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

啟動(dòng)minikube

minikube start 
--vm-driver=none 
--registry-mirror=https://registry.docker-cn.com

我們?cè)谂渲玫氖菃喂?jié)點(diǎn)kubernetes集群,并沒有安裝VM,所以–vm-driver=none
最后指定了鏡像源,當(dāng)然這里也可以更換為自己設(shè)置的鏡像源

tips: minikube v1.5.0對(duì)服務(wù)器有一定的要求,如果是虛擬機(jī)環(huán)境請(qǐng)?zhí)砑覥PU的個(gè)數(shù)(>=2)【最全國(guó)內(nèi)安裝教程】通過minikube運(yùn)行單節(jié)點(diǎn)Kubernetes集群_docker_03
運(yùn)行結(jié)束
【最全國(guó)內(nèi)安裝教程】通過minikube運(yùn)行單節(jié)點(diǎn)Kubernetes集群_linux_04
通過kubectl cluster-info查看集群是否正常工作【最全國(guó)內(nèi)安裝教程】通過minikube運(yùn)行單節(jié)點(diǎn)Kubernetes集群_阿里云_05
成功搭建單節(jié)點(diǎn)Kubernetes集群!

通過 stop 停止服務(wù)

minikube stop

問題小結(jié)

解決 minikube start 失敗

問題1

root@kies-G3-3579:~# minikube start 
> --vm-driver=none 
> --registry-mirror=https://registry.docker-cn.com
????  minikube v1.2.0 on linux (amd64)
????  Kubernetes downgrade is not supported, will continue to use v1.16.0
?  using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
????  Tip: Use 'minikube start -p <name>' to create a new cluster, or 'minikube delete' to delete this one.
????  Restarting existing none VM for "minikube" ...
?  Waiting for SSH access ...
????  Configuring environment for Kubernetes v1.16.0 on Docker 18.09.7
????  Relaunching Kubernetes v1.16.0 using kubeadm ... 

????  Error restarting cluster: running cmd: sudo kubeadm init phase kubeconfig all --config /var/lib/kubeadm.yaml: running command: sudo kubeadm init phase kubeconfig all --config /var/lib/kubeadm.yaml: exit status 1

????  Sorry that minikube crashed. If this was unexpected, we would love to hear from you:
????  https://github.com/kubernetes/minikube/issues/new

【最全國(guó)內(nèi)安裝教程】通過minikube運(yùn)行單節(jié)點(diǎn)Kubernetes集群_docker_06
問題2

$ minikube start 
--vm-driver=none 
--registry-mirror=https://registry.docker-cn.com
????  minikube v1.2.0 on linux (amd64)
?  using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
????  Tip: Use 'minikube start -p <name>' to create a new cluster, or 'minikube delete' to delete this one.
????  Restarting existing none VM for "minikube" ...
?  Waiting for SSH access ...
????  Configuring environment for Kubernetes v1.15.0 on Docker 18.09.7
????  Relaunching Kubernetes v1.15.0 using kubeadm ... 



????  Error restarting cluster: waiting for apiserver: timed out waiting for the condition

????  Sorry that minikube crashed. If this was unexpected, we would love to hear from you:
????  https://github.com/kubernetes/minikube/issues/new

【最全國(guó)內(nèi)安裝教程】通過minikube運(yùn)行單節(jié)點(diǎn)Kubernetes集群_linux_07
如果當(dāng)minikube start啟動(dòng)失敗了,嘗試執(zhí)行minikube delete

minikube delete

最后再重新start即可成功運(yùn)行

tips:
問題1請(qǐng)檢查是否在運(yùn)行minkube之前pull過一些非阿里的相關(guān)鏡像。

解決 corends 啟動(dòng)失敗

當(dāng)ministart start成功之后請(qǐng)觀察coredns是否啟動(dòng)成功
執(zhí)行kubectl get po -n kube-system

$ kubectl -n kube-system get po
NAME                               READY   STATUS             RESTARTS   AGE
coredns-6967fb4995-sgjtf           0/1     CrashLoopBackOff   22         92m
coredns-6967fb4995-v7dr7           0/1     CrashLoopBackOff   22         92m
etcd-minikube                      1/1     Running            0          91m
kube-addon-manager-minikube        1/1     Running            0          91m
kube-apiserver-minikube            1/1     Running            0          91m
kube-controller-manager-minikube   1/1     Running            0          91m
kube-proxy-5gsz5                   1/1     Running            0          92m
kube-scheduler-minikube            1/1     Running            0          91m
storage-provisioner                1/1     Running            1          92m

其中關(guān)于coredns的pod處于CrashhLoopBackOff狀態(tài),而且重啟了22次。

解決方法

  1. 修改coredns的configmapkubectl -n kube-system edit cm coredns

【最全國(guó)內(nèi)安裝教程】通過minikube運(yùn)行單節(jié)點(diǎn)Kubernetes集群_linux_08
注釋或者刪除掉loop之后保存退出。
2. 刪除coredns的全部pod(或者等待coredns pod重啟)

kubectl -n kube-system delete pod corednsxxxxxxxx
  1. 檢查是否成功運(yùn)行coredns pod(成功啟動(dòng)?。?/li>
$ kubectl -n kube-system get po                              
NAME                               READY   STATUS    RESTARTS   AGE
coredns-6967fb4995-lzkxz           1/1     Running   0          27s
coredns-6967fb4995-zfnpw           1/1     Running   0          48s
etcd-minikube                      1/1     Running   0          94m
kube-addon-manager-minikube        1/1     Running   0          95m
kube-apiserver-minikube            1/1     Running   0          94m
kube-controller-manager-minikube   1/1     Running   0          95m
kube-proxy-5gsz5                   1/1     Running   0          96m
kube-scheduler-minikube            1/1     Running   0          94m
storage-provisioner                1/1     Running   1          95m

啟動(dòng)報(bào)錯(cuò)失敗

報(bào)錯(cuò)信息:

! Ubuntu 16.04 上的 minikube v1.9.2
* 根據(jù)用戶配置使用 none 驅(qū)動(dòng)程序
X Sorry, Kubernetes v1.18.0 requires conntrack to be installed in root's path

解決方法
sudo apt install conntrack
然后重新start

關(guān)于 dashboard

請(qǐng)通過minikube dashboard打開dashboard
【最全國(guó)內(nèi)安裝教程】通過minikube運(yùn)行單節(jié)點(diǎn)Kubernetes集群_kubernetes_09

關(guān)于作者

【最全國(guó)內(nèi)安裝教程】通過minikube運(yùn)行單節(jié)點(diǎn)Kubernetes集群_kubernetes_10

?

本文摘自 :https://blog.51cto.com/u

開通會(huì)員,享受整站包年服務(wù)立即開通 >