安装步骤

  1. 准备三台机器, 系统环境为centos7.8
  2. 配置hostname与hosts
    示例:
# 第一台机器执行
hostnamectl set-hostname master
# 第二台机器执行
hostnamectl set-hostname node01
# 第三台机器执行
hostnamectl set-hostname node02

替换为实际ip

echo -e '192.168.1.100 master
192.168.1.101 node01
192.168.1.102 node02
' >> /etc/hosts

安装docker

yum -y remove docker-*
yum -y remove containerd*
rm -rf /var/lib/docker

yum list installed |grep docker
rpm -qa |grep docker

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

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


sudo yum install -y docker-ce-20.10.1 docker-ce-cli-20.10.1 containerd.io docker-compose-plugin

sudo systemctl start docker
sudo systemctl enable docker

echo '{
        "exec-opts": ["native.cgroupdriver=systemd"]
      }' > /etc/docker/daemon.json

sudo systemctl restart docker

配置防火墙与网路

systemctl stop firewalld && systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config && setenforce 0
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab

cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF

sysctl --system

安装kubeadm

cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

yum install -y kubelet-1.23.0 kubeadm-1.23.0 kubectl-1.23.0
systemctl enable kubelet

以上步骤需要在每个节点执行;

初始化主节点(在master节点执行)

kubeadm init \
  --kubernetes-version 1.23.0 \
  --apiserver-advertise-address=0.0.0.0 \
  --service-cidr=10.96.0.0/16 \
  --pod-network-cidr=10.244.0.0/16 \
  --image-repository registry.aliyuncs.com/google_containers

## 安装网络插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

从节点加入master(从节点执行)

复制主节点初始化完成后输出的信息,类似如下的命令,在从节点执行;

kubeadm join 172.17.12.205:6443 --token xctyy8.evcnipt56vp3b9pn --discovery-token-ca-cert-hash sha256:7e1eba8c7c799912c28f88853d36efeaab704734f82e8804f085079c8330ac38

验证

主节点执行

kubectl get nodes
Logo

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

更多推荐