1. master and worker 关闭防火墙以及SElinux

防火墙

firewall-cmd --state	    #查看防火墙状态
systemctl stop firewalld.service    	#停止firewall
systemctl disable firewalld.service    	#禁止firewall开机启动

SElinux

getenforce	#查看selinux状态
setenforce 0	#临时关闭selinux
sed -i 's/^ *SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config	#永久关闭(需重启系统)

2.允许 iptables 检查桥接流量

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system

================================ 补充 ====================================

x.修改host主机名并配置host文件 , 设置主机间互通

x.1修改host主机名

设置主机名

hostnamectl set-hostname master

查看主机名

more /etc/hostname

x.2配置host文件

cat >> /etc/hosts << EOF
172.27.9.131    master
172.27.9.135    node01
172.27.9.136    node02
EOF
more /etc/hosts

x.3设置主机间互通

配置主机之间无密码登录
生成ssh 密钥对,一路回车,不输入密码

ssh-keygen -t rsa

把本地的ssh公钥文件安装到远程主机对应的账户

ssh-copy-id -i .ssh/id_rsa.pub k8s-master1
ssh-copy-id -i .ssh/id_rsa.pub k8s-master2
ssh-copy-id -i .ssh/id_rsa.pub k8s-master3
ssh-copy-id -i .ssh/id_rsa.pub k8s-node1

=========================================================================

3.install Container runtimes

{安装 docker 网址}

1)Install the yum-utils package

 sudo yum install -y yum-utils
 sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

2)Install Docker Engine

 sudo yum install docker-ce docker-ce-cli containerd.io

3)Start Docker

sudo systemctl start docker

4)Verify that Docker Engine is installed correctly by running the hello-world image.

docker run hello-world

5)配置 Docker 守护程序,尤其是使用 systemd 来管理容器的 cgroup

sudo mkdir /etc/docker
cat <<EOF | sudo tee /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF

6)重新启动 Docker 并启用开机自启动

sudo systemctl enable docker
sudo systemctl daemon-reload
sudo systemctl restart docker

4.install kubeadm、kubelet、kubectl

1)基于CentOS

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF

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

sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

sudo systemctl enable --now kubelet
Logo

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

更多推荐