minikube部署k8s - 图1

准备工作

  • 满足安装 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。

  1. cat << EOF | tee /etc/modules-load.d/k8s.conf
  2. br_netfilter
  3. EOF
  4. # 关闭防火墙
  5. systemctl stop firewalld && systemctl disable firewalld
  6. cat << EOF | tee /etc/sysctl.d/k8s.conf
  7. net.bridge.bridge-nf-call-ip6tables = 1
  8. net.bridge.bridge-nf-call-iptables = 1
  9. net.ipv4.ip_forward = 1
  10. EOF
  11. sysctl --system

执行sysctl -p 时出现如下报错,应执行 modprobe br_netfilter ,加载相应的模块。

  1. # sysctl -p
  2. sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-ip6tables: No such file or directory
  3. sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-iptables: No such file or directory

设置selinux

  1. # 将 SELinux 设置为 permissive 模式(相当于将其禁用)
  2. setenforce 0
  3. sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

关闭swap

先通过free查看有无swap

  1. swapoff -a
  2. sed -i "s/\/dev\/mapper\/centos-swap/\#\/dev\/mapper\/centos-swap/g" /etc/fstab

部署docker

安装docker

  1. # 配置yum源
  2. curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  3. # 安装
  4. yum makecache
  5. yum install docker-ce -y

docker配置镜像加速

  1. mkdir -p /etc/docker
  2. cat << EOF | tee /etc/docker/daemon.json
  3. {
  4. "registry-mirrors": ["https://5twf62k1.mirror.aliyuncs.com"],
  5. "exec-opts": ["native.cgroupdriver=systemd"]
  6. }
  7. EOF
  8. systemctl daemon-reload
  9. systemctl enable docker && systemctl restart docker

安装kubectl

  1. curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
  2. install kubectl /usr/local/bin/kubectl

启动minikube

  1. minikube start --image-mirror-country='cn' --kubernetes-version='1.23.6' --force

启动dashboard

  1. # 开启dashboard
  2. [root@vm101 ~]# minikube dashboard
  3. 🤔 正在验证 dashboard 运行情况 ...
  4. 🚀 Launching proxy ...
  5. 🤔 正在验证 proxy 运行状况 ...
  6. http://127.0.0.1:43415/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
  7. # 开启dashboard代理
  8. [root@vm101 ~]# kubectl proxy --port=43415 --address='192.168.164.101' --accept-hosts='^.*' &
  9. # 转发
  10. kubectl port-forward --address 0.0.0.0 service/hello-minikube 7080:8080
  11. Forwarding from 0.0.0.0:7080 -> 8080
  12. Handling connection for 7080
  13. Handling connection for 7080