准备工作
- 满足安装 Docker 项目所需的要求,比如 64 位的 Linux 操作系统、3.10 及以上的内核版本;CentOS 7.8.2003
- x86 或者 ARM 架构均可;
- 单机可用资源建议 2 核 CPU、8 GB 内存
环境预设
关闭 iptables 和 内核依赖
通过 lsmod | grep br_netfilter 确认 br_netfilter 是否存在。
由于 iptables 被绕过而导致流量无法正确路由的问题。应该确保 在 sysctl
配置中的 net.bridge.bridge-nf-call-iptables
被设置为 1。
cat << EOF | tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
# 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
cat << EOF | tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
执行sysctl -p
时出现如下报错,应执行 modprobe br_netfilter
,加载相应的模块。
# sysctl -p
sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-ip6tables: No such file or directory
sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-iptables: No such file or directory
设置selinux
# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
关闭swap
先通过free
查看有无swap
swapoff -a
sed -i "s/\/dev\/mapper\/centos-swap/\#\/dev\/mapper\/centos-swap/g" /etc/fstab
部署docker
安装docker
# 配置yum源
curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装
yum makecache
yum install docker-ce -y
docker配置镜像加速
mkdir -p /etc/docker
cat << EOF | tee /etc/docker/daemon.json
{
"registry-mirrors": ["https://5twf62k1.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
systemctl daemon-reload
systemctl enable docker && systemctl restart docker
安装kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
install kubectl /usr/local/bin/kubectl
启动minikube
minikube start --image-mirror-country='cn' --kubernetes-version='1.23.6' --force
启动dashboard
# 开启dashboard
[root@vm101 ~]# minikube dashboard
🤔 正在验证 dashboard 运行情况 ...
🚀 Launching proxy ...
🤔 正在验证 proxy 运行状况 ...
http://127.0.0.1:43415/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
# 开启dashboard代理
[root@vm101 ~]# kubectl proxy --port=43415 --address='192.168.164.101' --accept-hosts='^.*' &
# 转发
kubectl port-forward --address 0.0.0.0 service/hello-minikube 7080:8080
Forwarding from 0.0.0.0:7080 -> 8080
Handling connection for 7080
Handling connection for 7080