【最全国内安装教程】通过minikube运行单节点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,这更适用于国内环境
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
我们在配置的是单节点kubernetes集群,并没有安装VM,所以–vm-driver=none
最后指定了镜像源,当然这里也可以更换为自己设置的镜像源
tips: minikube v1.5.0对服务器有一定的要求,如果是虚拟机环境请添加CPU的个数(>=2)
运行结束
通过kubectl cluster-info
查看集群是否正常工作
成功搭建单节点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启动失败了,尝试执行minikube delete
minikube delete
最后再重新start
即可成功运行
tips:
问题1请检查是否在运行minkube之前pull过一些非阿里的相关镜像。
解决 corends 启动失败
当ministart start
成功之后请观察coredns是否启动成功
执行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状态,而且重启了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(成功启动!)
$ 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