虚拟机使用minikube搭建k8s集群

一、安装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
posted @ 2024-09-05 10:30  猝死的路上  阅读(100)  评论(0编辑  收藏  举报