?
【最全國內安裝教程】通過minikube運行單節(jié)點Kubernetes集群
?
前言
minikube的方便不用我過多言語了吧,一些書上都是基于國外資源進行安裝部署。通過在網上沖浪后,我整理出來了一份國內安裝minikube的詳細過程
從零開始安裝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鏡像下載源
通過阿里云控制臺配置Docker鏡像源(配置屬于自己的Docker鏡像源)
https://cr.console.aliyun.com/cn-shanghai/instances/mirrors
ps:也可以省略此步,將Docker鏡像源修改為https://registry.docker-cn.com即可
修改/etc/docker/daemon.json
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://registry.docker-cn.com"]
# 最好更換為自己設置鏡像源!
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
通過阿里云下載minikube
阿里云修改了官方的minikube,這更適用于國內環(huán)境
https://github.com/AliyunContainerService/minikube/wiki
這個wiki會更新最新的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/
啟動minikube
minikube start
--vm-driver=none
--registry-mirror=https://registry.docker-cn.com
我們在配置的是單節(jié)點kubernetes集群,并沒有安裝VM,所以–vm-driver=none
最后指定了鏡像源,當然這里也可以更換為自己設置的鏡像源
tips: minikube v1.5.0對服務器有一定的要求,如果是虛擬機環(huán)境請?zhí)砑覥PU的個數(>=2)
運行結束
通過kubectl cluster-info
查看集群是否正常工作
成功搭建單節(jié)點Kubernetes集群!
通過 stop
停止服務
minikube stop
問題小結
解決 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
問題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
如果當minikube start啟動失敗了,嘗試執(zhí)行minikube delete
minikube delete
最后再重新start
即可成功運行
tips:
問題1請檢查是否在運行minkube之前pull過一些非阿里的相關鏡像。
解決 corends 啟動失敗
當ministart start
成功之后請觀察coredns是否啟動成功
執(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
其中關于coredns的pod處于CrashhLoopBackOff狀態(tài),而且重啟了22次。
解決方法
- 修改coredns的configmap
kubectl -n kube-system edit cm coredns
注釋或者刪除掉loop之后保存退出。
2. 刪除coredns的全部pod(或者等待coredns pod重啟)
kubectl -n kube-system delete pod corednsxxxxxxxx
- 檢查是否成功運行coredns pod(成功啟動?。?/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
啟動報錯失敗
報錯信息:
! Ubuntu 16.04 上的 minikube v1.9.2
* 根據用戶配置使用 none 驅動程序
X Sorry, Kubernetes v1.18.0 requires conntrack to be installed in root's path
解決方法sudo apt install conntrack
然后重新start
關于 dashboard
請通過minikube dashboard
打開dashboard
關于作者
?
本文摘自 :https://blog.51cto.com/u