虛擬機器使用minikube搭建k8s叢集

猝死的路上發表於2024-09-05

一、安裝docker(目前登入的是root使用者)

1、下載 https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

本次使用 20.10.9版本

2、解壓

tar xfz docker-20.10.9.tgz

3、複製到 /usr/bin

cp -rf docker/* /usr/bin/

4、將docker註冊為系統服務

vi /usr/lib/systemd/system/docker.service

寫入內容

點選檢視內容
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by do cker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=onfailure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target

儲存

5、新增檔案許可權

chmod u+x /usr/lib/systemd/system/docker.service

6、過載unit配置檔案

systemctl daemon-reload

7、啟動docker

systemctl enable docker

8、檢視docker狀態

systemctl status docker

二、安裝kubectl v1.30.0

1、新建使用者

useradd kube

2、給予許可權

vi /etc/sudoers

在這兩行下面

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL

新增內容

kube     ALL=(ALL)       NOPASSWD:ALL

儲存,這裡需要強制儲存 wq!

3、切換使用者

su kube

接下來所有操作都是kube使用者

4、新建組docker,kube使用者加入docker組

sudo groupadd docker
sudo usermod -aG docker $USER && newgrp docker

5、下載

curl -LO https://dl.k8s.io/release/v1.30.0/bin/linux/amd64/kubectl

6、安裝 kubectl

sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

7、測試是否安裝成功

kubectl version --client

三、安裝minikube

1、下載(如果不能下載去阿里雲下載)

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

2、安裝

sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64

3、測試是否安裝成功

minikube version

4、啟動

minikube start

啟動過程大致如下,會自動拉取映象

**在centos7下會有pod啟動不起來的情況**
issues
按照官方說法是kubectl的版本和centos7的相容性問題,預設安裝的minikube版本為 1.33.0,kubectl的版本為1.30.0
降低kubectl的版本即可,使用如下命令啟動

minikube start --container-runtime=docker --kubernetes-version=1.28.3 -p k8s-1.28.3

相關文章