1、windows环境下安装vmbox虚拟机
2、下载ubuntu 服务器镜像-ubuntu-22.04.3-live-server-amd64.iso
3、新建3个ubuntu虚拟环境,分别命名为ubuntu02,ubuntu03,ubuntu04,网卡设置为桥接模式,假设主机ip为192.168.1.6,三个环境对应ip分别为192.168.1.7,192.168.1.8,192.168.1.9,分别修改/etc/hostname为主机名
4、安装ssh环境,设置允许root用户登录
apt install openssh-server -y
5、使用tabby创建三个服务器的ssh配置,连接三个服务器
6、ubuntu02作为控制主机,安装microk8s服务
sudo snap install microk8s --classic
microk8s status --wait-ready
国内用户会在这里卡住,因为下载不了镜像,解决方案参考https://microk8s.io/docs/registry-private,具体操作如下
# create a directory with the registry name
sudo mkdir -p /var/snap/microk8s/current/args/certs.d/registry.k8s.io
# create the hosts.toml file pointing to the mirror
echo '
server = "registry.k8s.io"
[host."https://registry.aliyuncs.com/v2/google_containers"]
capabilities = ["pull", "resolve"]
override_path = true
' | sudo tee -a /var/snap/microk8s/current/args/certs.d/registry.k8s.io/hosts.toml
# A restart of the containerd daemon helps but is not required, since changes should take effect immediately.
sudo snap restart microk8s
7、ubuntu02启动必要服务,包括面板任务
microk8s enable dashboard dns registry istio
# 使用microk8s kubectl get pods -A 发现有dashboard服务镜像metrics-server无法拉取,从阿里云拉取并tag即可
microk8s ctr image pull registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server:v0.5.2
microk8s ctr image tag registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server:v0.5.2 registry.k8s.io/metrics-server/metrics-server:v0.5.2
8 、ubuntu03和ubuntu04作为服务节点,安装步骤同理,如下
sudo snap install microk8s --classic
microk8s status --wait-ready # 设置使用国内源,参考主机
microk8s enable dns registry istio # 启动必要服务,排除面板服务
9、主机ubuntu02添加节点ubuntu03,执行命令microk8s add-node,加入信息如下:
From the node you wish to join to this cluster, run the following:
microk8s join 192.168.1.7:25000/8f6f92d867d4244a5da27fb5c4d150f5/fd98fbd2e263
Use the '--worker' flag to join a node as a worker not running the control plane, eg:
microk8s join 192.168.1.7:25000/8f6f92d867d4244a5da27fb5c4d150f5/fd98fbd2e263 --worker
If the node you are adding is not reachable through the default interface you can use one of the following:
microk8s join 192.168.1.7:25000/8f6f92d867d4244a5da27fb5c4d150f5/fd98fbd2e263
microk8s join 2408:823c:5616:a414:a00:27ff:fe4f:7e91:25000/8f6f92d867d4244a5da27fb5c4d150f5/fd98fbd2e263
# 在ubuntu03节点作为woker执行加入操作
microk8s join 192.168.1.7:25000/8f6f92d867d4244a5da27fb5c4d150f5/fd98fbd2e263 --worker
如果主机没有设置dns关系,会出现如下提示报错:
Connection failed. The hostname (ubuntu03) of the joining node does not resolve to the IP "192.168.1.8". Refusing join (400)
这个时候需要主机hosts指明关系,将如下内容加入/etc/hosts中,然后使用service nscd restart命令使其生效,重复如上操作即可完成加入
192.168.1.7 ubuntu02
192.168.1.8 ubuntu03
192.168.1.9 ubuntu04
10、如同步骤9,添加节点ubuntu04,然后在主机使用命令microk8s kubectl get no可以看到加入集群的所有节点,即完成集群部署:
NAME STATUS ROLES AGE VERSION
ubuntu03 Ready <none> 3m22s v1.27.4
ubuntu02 Ready <none> 105m v1.27.4
ubuntu04 Ready <none> 33s v1.27.4
网友评论