1、环境说明(安装时配置IP及主机名)
  192.168.3.107    master    rockylinux8.6最小化安装    控制节点
  192.168.3.108    node1    rockylinux8.6最小化安装    工作节点
  192.168.3.109    node2    rockylinux8.6最小化安装    工作节点
2、关闭selinux,firewalld及swap分区(在三台设备上执行)

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl disable firewalld
swapoff -a
reboot


注:swapoff -a 为临时关闭swap分区。永久关闭swap分区,vi /etc/fstab  注释swap分区一行

3、修改/etc/hosts文件,增加如下三行(三台设备)
192.168.3.114  master
192.168.3.115  node1
192.168.3.116  node2

4、更改yum源为阿里云(三台设备执行)

sed -e 's|^mirrorlist=|#mirrorlist=|g' \
    -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
    -i.bak \
    /etc/yum.repos.d/Rocky-*.repo
 
dnf makecache


5、配置命令补全及vim工具(三台设备执行)

dnf install -y wget bash-completion vim

6、配置免密登录(master上执行,可省)

ssh-keygen
ssh-copy-id node1
ssh-copy-id node2


7、配置时间同步(三台设备执行)

dnf install -y chrony

更改  /etc/chrony.conf  配置文件

将pool 2.pool.ntp.org iburst

改为

server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp1.tencent.com iburst
server ntp2.tencent.com iburst

systemctl enable --now chronyd
chronyc sources
date
8、修改内核参数(三台设备上执行)

modprobe br_netfilter
lsmod | grep br_netfilter
 
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 -p /etc/sysctl.d/k8s.conf

 9、安装依整包及配置docker源、k8s源(三台设备执行)

dnf install -y yum-utils device-mapper-persistent-data lvm2 ipvsadm net-tools
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
 
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=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
dnf makecache

10、安装docker及cri-docker(三台设备执行)

dnf install -y docker-ce
systemctl enable --now cri-docker

tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://0x3urqgf.mirror.aliyuncs.com"]
}
EOF

systemctl daemon-reload
systemctl restart docker

下载安装包:cri-dockerd-0.2.3-3.el7.x86_64.rpm

wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.2.3/cri-dockerd-0.2.3-3.el7.x86_64.rpm
rpm -ivh cri-dockerd-0.2.3-3.el7.x86_64.rpm

sed -e 's#ExecStart=.*#ExecStart=/usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.7#g' /usr/lib/systemd/system/cri-docker.service 

systemctl daemon-reload
systemctl enable --now cri-docker

11、安装kubelet kubeadm kubectl

master节点

dnf install  -y kubelet-1.25.0 kubeadm-1.25.0 kubectl-1.25.0
systemctl enable kubelet

node1 及node2上执行

dnf install  -y kubelet-1.25.0 kubeadm-1.25.0
systemctl enable kubelet

12、初始化K8S集群

kubeadm init \
  --apiserver-advertise-address=192.168.3.107 \
  --image-repository registry.aliyuncs.com/google_containers \
  --kubernetes-version v1.25.0 \
  --service-cidr=10.16.0.0/16 \
  --pod-network-cidr=10.26.0.0/16 \
  --ignore-preflight-errors=all \
  --cri-socket /var/run/cri-dockerd.sock

执行命令

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

k8s命令补全

source <(kubeadm completion bash)
echo "source <(kubeadm completion bash)" >> ~/.bashrc
source ~/.bashrc 

 13、工作节点加入集群

master节点执行

kubeadm token create --print-join-command

两台Node节点执行

kubeadm join 192.168.3.107:6443 --token 4twkui.tlzawgwjn1ytdk8u --discovery-token-ca-cert-hash sha256:6da1eafda7d876be3ea04690bc7acd616314313d4389029302d5db60b415a7af  --cri-socket /var/run/cri-dockerd.sock

master节点查看

kubectl get nodes

14、安装网络组件

master节点执行

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

kubectl get pods -n kube-system -w

15、验证

kubectl get nodes
kubectl get componentstatuses
kubectl cluster-info
kubectl -n kube-system get pod

Logo

开源、云原生的融合云平台

更多推荐