1氢烘、windows環(huán)境下安裝vmbox虛擬機(jī)
2怀偷、下載ubuntu 服務(wù)器鏡像-ubuntu-22.04.3-live-server-amd64.iso
3、新建3個(gè)ubuntu虛擬環(huán)境播玖,分別命名為ubuntu02,ubuntu03,ubuntu04,網(wǎng)卡設(shè)置為橋接模式,假設(shè)主機(jī)ip為192.168.1.6椎工,三個(gè)環(huán)境對(duì)應(yīng)ip分別為192.168.1.7,192.168.1.8,192.168.1.9,分別修改/etc/hostname為主機(jī)名
4蜀踏、安裝ssh環(huán)境,設(shè)置允許root用戶登錄
apt install openssh-server -y
5维蒙、使用tabby創(chuàng)建三個(gè)服務(wù)器的ssh配置,連接三個(gè)服務(wù)器
6果覆、ubuntu02作為控制主機(jī)颅痊,安裝microk8s服務(wù)
sudo snap install microk8s --classic
microk8s status --wait-ready
國(guó)內(nèi)用戶會(huì)在這里卡住,因?yàn)橄螺d不了鏡像局待,解決方案參考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啟動(dòng)必要服務(wù),包括面板任務(wù)
microk8s enable dashboard dns registry istio
# 使用microk8s kubectl get pods -A 發(fā)現(xiàn)有dashboard服務(wù)鏡像metrics-server無(wú)法拉取钳榨,從阿里云拉取并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作為服務(wù)節(jié)點(diǎn),安裝步驟同理重绷,如下
sudo snap install microk8s --classic
microk8s status --wait-ready # 設(shè)置使用國(guó)內(nèi)源沸停,參考主機(jī)
microk8s enable dns registry istio # 啟動(dòng)必要服務(wù),排除面板服務(wù)
9昭卓、主機(jī)ubuntu02添加節(jié)點(diǎn)ubuntu03愤钾,執(zhí)行命令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節(jié)點(diǎn)作為woker執(zhí)行加入操作
microk8s join 192.168.1.7:25000/8f6f92d867d4244a5da27fb5c4d150f5/fd98fbd2e263 --worker
如果主機(jī)沒有設(shè)置dns關(guān)系候醒,會(huì)出現(xiàn)如下提示報(bào)錯(cuò):
Connection failed. The hostname (ubuntu03) of the joining node does not resolve to the IP "192.168.1.8". Refusing join (400)
這個(gè)時(shí)候需要主機(jī)hosts指明關(guān)系睹晒,將如下內(nèi)容加入/etc/hosts中蛾狗,然后使用service nscd restart命令使其生效粱檀,重復(fù)如上操作即可完成加入
192.168.1.7 ubuntu02
192.168.1.8 ubuntu03
192.168.1.9 ubuntu04
10抖韩、如同步驟9,添加節(jié)點(diǎn)ubuntu04,然后在主機(jī)使用命令microk8s kubectl get no可以看到加入集群的所有節(jié)點(diǎn),即完成集群部署:
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