引言
MicroK8s在众多K8s发行版中算是比较易用且轻量的,适合快速搭建使用,是Ubuntu发行版中默认的,以下是具体步骤
安装
如果你已经按之前文章UbuntuServer Setup设置准备好了当前系统环境,下面是具体操作命令
# snap国内安装速度挺快
$ sudo snap install microk8s --classic
# 检查启动是否成功,此处容易出现镜像无法拉取问题
$ microk8s status --wait-ready
以上两条命令成功执行后就算安装完成了。
配置集群
完成K8s安装后,我们开启集群的配置,此处使用三台虚拟机
10.0.0.1 cuipi
10.0.0.2 jiangjiang
10.0.0.3 peento
在 cuipi 节点执行节点添加声明 microk8s add-node
,会产生以下添加日志
From the node you wish to join to this cluster, run the following:
microk8s join 10.0.0.1:25000/xxxxx/xxx
Use the '--worker' flag to join a node as a worker not running the control plane, eg:
microk8s join 10.0.0.1:25000/xxxxx/xxx --worker
If the node you are adding is not reachable through the default interface you can use one of the following:
microk8s join 10.0.0.1:25000/xxxxx/xxx
在另外两台节点jiangjiang、peento中分别执行以下命令,添加为工作节点
microk8s join 10.0.0.1:25000/xxxxx/xxx --worker
执行成功后,集群就组建完成了,此处我们在cuipi节点上通过下面命令看一下当前的集群情况
$ microk8s kubectl get nodes
NAME STATUS ROLES AGE VERSION
peento Ready <none> 208d v1.30.11
jiangjiang Ready <none> 604d v1.27.16
cuipi Ready <none> 605d v1.27.16
常见问题
镜像无法拉取
通过执行命令kubectl describe pod --all-namespaces
看到,镜像xxxx
无法成功拉取
"xxxx": failed to pull image "xxxx": failed to pull and unpack image "xxxx": failed to resolve reference "xxxx": failed to do request: Head "xxxx": dial tcp xxx.xxx.xxx.xxx:443: i/o timeout
此处我们需要有可以访问xxxx镜像的网络代理,或者下载了镜像的离线文件
# 代理
$ https_proxy=10.0.1.1:1080 microk8s ctr image pull xxxx
# 文件
$ microk8s ctr images import xxxx.tar