# K8S环境准备
1、关闭 Swap 
如果不关闭,默认配置的 kubelet 将无法启动
swapoff -a 
sed -i 's/.*swap.*/#&/' /etc/fstab
2、禁用 SELINUX
setenforce 0 
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux 
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config 
sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/sysconfig/selinux 
sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/selinux/config
3、防火墙开8080端口
firewall-cmd --permanent --add-port=8080/tcp
systemctl restart firewalld.service
4、创建/etc/sysctl.d/k8s.conf 文件,添加如下内容:
cat >>/etc/sysctl.d/k8s.conf<< OFF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
OFF
执行如下命令使修改生效:
modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf
5、加载 ipvs 模块 
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
lsmod | grep ip_vs
lsmod | grep nf_conntrack_ipv4

yum install -y ipvsadm ipset

# Docker 安装
# 安装必要的一些系统工具
yum install -y yum-utils device-mapper-persistent-data lvm2

# 查看目前官方仓库的 docker 版本。
centos 8:yum remove podman -y
centos 7:
yum list docker-ce.x86_64 --showduplicates |sort -r #从高到低列出 Docker-ce 的版本
yum remove docker-ce docker-ce-cli containerd.io -y
yum install docker-ce docker-ce-cli containerd.io -y

systemctl start docker
systemctl enable docker --now
设置 Docker 镜像加速器
修改 docker 配置以适应 kubelet
vi /etc/docker/daemon.json 
{
 "registry-mirrors": ["https://registry.cn-hangzhou.aliyuncs.com"],
 "exec-opts": ["native.cgroupdriver=systemd"]
}
systemctl daemon-reload
systemctl restart docker

# kubernetes 安装
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
EOF
yum list kubeadm --showduplicates |sort -r
yum install kubeadm-1.21.5 kubectl-1.21.5 kubelet-1.21.5 -y

测试:
节点对应的位置即可使用 kubectl 命令行工具了
kubectl version
启动 kubelet
systemctl daemon-reload
systemctl start kubelet.service
systemctl enable kubelet.service
systemctl status kubelet.service

kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version=v1.21.5 --pod-network-cidr=10.10.0.0/16 --service-cidr=10.20.0.0/16 --apiserver-advertise-address=192.168.56.1

Your Kubernetes control-plane has initialized successfully!

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐