ubuntu利用minikube搭建单点k8s
目前安装k8s的方式有如下几种:kubeadm(新版本可以用于生产环境,旧版本存在风险)Docker Desktop(如果是本地桌面系统推荐这种方式)minikube(本地快速单机部署,体验最简版的k8s,不推荐在生产环境上使用)本文选择安装minikube的方式搭建最简k8s环境,官方教程:https://minikube.sigs.k8s.io/docs/start/安装前准备:2 CPUs
目前安装k8s的方式有如下几种:
- kubeadm(新版本可以用于生产环境,旧版本存在风险)
- Docker Desktop(如果是本地桌面系统推荐这种方式)
- minikube(本地快速单机部署,体验最简版的k8s,不推荐在生产环境上使用)
本文选择安装minikube的方式搭建最简k8s环境,官方教程:https://minikube.sigs.k8s.io/docs/start/
安装前准备:
- 2 CPUs or more
- 2GB of free memory
- 20GB of free disk space
- Internet connection
- Container or virtual machine manager, such as: Docker, Hyperkit, Hyper-V, KVM, Parallels, Podman, VirtualBox, or VMWare
注意事项:
通过阅读官方教程得知,用minikube搭建k8s环境时,既支持通过虚拟化技术运行,也可以选择不通过虚拟化技术直接运行在服务器上。所以对于一些不支持虚拟化技术的云服务器实例,只能通过后者安装运行k8s,也无须安装KVM或VirtualBox等虚拟化工具,不过还是依赖于Docker环境,所以需要先安装Docker,具体可参考Ubuntu上安装Docker。
Note: Minikube also supports a
--vm-driver=none
option that runs the Kubernetes components on the host and not in a VM. Using this driver requires Docker and a Linux environment but not a hypervisor. It is recommended to use the apt installation of docker from Docker, when using the none driver. The snap installation of docker does not work with minikube.
安装
1、安装kubectl
1.1、下载kubectl命令行
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
如果想下载指定版本,则将$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
替换成指定版本,如:
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/amd64/kubectl
1.2、 赋予权限
chmod +x ./kubectl
1.3、 将命令行移动到path
下
sudo mv ./kubectl /usr/local/bin/kubectl
1.4、 测试
root@myubuntu01:~# kubectl version --client
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:20:10Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
2、 安装minikube
2.1、下载并安装x86的minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
2.2、 启动minikube
minikube启动k8s环境时需要从k8s.gcr.io
拉取kube-apiserver
、kube-controller-manager
、kube-scheduler
等docker镜像进行部署。而由于墙的问题从阿里云的云端机器上是无法访问k8s.gcr.io
的。
root@myubuntu01:~# minikube start --help
--image-mirror-country='': Country code of the image mirror to be used. Leave empty to use the global one. For
Chinese mainland users, set it to cn.
--image-repository='': Alternative image repository to pull docker images from. This can be used when you have
limited access to gcr.io. Set it to "auto" to let minikube decide one for you. For Chinese mainland users, you may use
local gcr.io mirrors such as registry.cn-hangzhou.aliyuncs.com/google_containers
因此,启动命令行为:
minikube start --vm-driver=none --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
2.3、 测试
root@myubuntu01:~# kubectl get po -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-54d67798b7-r58t7 1/1 Running 0 24m
kube-system etcd-myubuntu01 1/1 Running 0 24m
kube-system kube-apiserver-myubuntu01 1/1 Running 0 24m
kube-system kube-controller-manager-myubuntu01 1/1 Running 0 24m
kube-system kube-proxy-dtq5l 1/1 Running 0 24m
kube-system kube-scheduler-myubuntu01 1/1 Running 0 24m
kube-system storage-provisioner 1/1 Running 0 25m
异常解析
1、Sorry, Kubernetes 1.20.0 requires conntrack to be installed in root’s path
root@myubuntu01:~# minikube start --vm-driver=none --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
* minikube v1.16.0 on Ubuntu 20.04
* Using the none driver based on user configuration
X Exiting due to GUEST_MISSING_CONNTRACK: Sorry, Kubernetes 1.20.0 requires conntrack to be installed in root's path
此问题的原因是操作系统中缺少conntrack
导致
apt-get install conntrack
参考文档
更多推荐
所有评论(0)