sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
yum install iproute-tc -y
yum -y install wget curl net-tools sysstat bind-utils
reboot
# 设置所需的 sysctl 参数,参数在重新启动后保持不变
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF
# 应用 sysctl 参数而不重新启动
sudo sysctl --system
[root@node00 ~]# wget http://download.9421.ltd/backup_dir/containerd-2.0.0-linux-amd64.tar.gz
[root@node00 ~]# tar xf containerd-2.0.0-linux-amd64.tar.gz
[root@node00 ~]# mv bin/* /usr/local/bin/
[root@node00 ~]# wget https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
[root@node00 ~]# mkdir -p /usr/local/lib/systemd/system/
[root@node00 ~]# mv containerd.service /usr/local/lib/systemd/system/
[root@node00 ~]# systemctl daemon-reload
[root@node00 ~]# systemctl enable --now containerd
[root@node00 ~]# wget http://download.9421.ltd/backup_dir/runc.amd64
[root@node00 ~]# install -m 755 runc.amd64 /usr/local/sbin/runc
[root@node00 ~]# wget http://download.9421.ltd/backup_dir/cni-plugins-linux-amd64-v1.6.0.tgz
[root@node00 ~]# mkdir -p /opt/cni/bin
[root@node00 ~]# tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.6.0.tgz
[root@node00 ~]# echo 'export PATH=$PATH:/opt/cni/bin' >> /etc/profile
[root@node00 ~]# source /etc/profile
[root@node00 ~]# mkdir /etc/containerd
[root@node00 ~]# containerd config default > /etc/containerd/config.toml
[root@node00 ~]# sed -i 's/registry.k8s.io/registry.aliyuncs.com\/google_containers/' /etc/containerd/config.toml
[root@node00 ~]# systemctl daemon-reload
[root@node00 ~]# systemctl restart containerd
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.31/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.31/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
EOF
[root@node00 ~]# yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
[root@node00 ~]# systemctl enable --now kubelet
给本机网卡添加VIP地址,用于初始化。
ip addr add 172.30.11.19/16 dev ens18 ip addr del 172.30.11.19/16 dev ens18
[root@node00 ~]# kubeadm config print init-defaults > /etc/kubernetes/init-default.yaml
[root@node00 ~]# sed -i 's/registry.k8s.io/registry.aliyuncs.com\/google_containers/' /etc/kubernetes/init-default.yaml
#master 执行 IP换成本机地址
[root@node00 ~]# sed -i 's/1.2.3.4/172.30.11.10/' /etc/kubernetes/init-default.yaml
[root@node00 ~]# kubeadm init --image-repository registry.aliyuncs.com/google_containers --control-plane-endpoint "172.30.11.19:6443" --upload-certs
[root@node00 ~]# mkdir -p $HOME/.kube
[root@node00 ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@node00 ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config
[root@node01 ~]# kubeadm join 172.30.11.19:6443 --token kihb7i.d90wk3t958pyli32 \
> --discovery-token-ca-cert-hash sha256:8f22e90937513ce622d54a865ee1debf41a0a253f40a79fe87ae395e5ee2a1b8 \
> --control-plane --certificate-key ad430287207271a7ad116b5ef31c9e0899c85503e9104cc9dff44c41e4d5537c
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[preflight] Running pre-flight checks before initializing the new control plane instance
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action beforehand using 'kubeadm config images pull'
W1119 19:24:57.642998 1570 checks.go:846] detected that the sandbox image "" of the container runtime is inconsistent with that used by kubeadm.It is recommended to use "registry.aliyuncs.com/google_containers/pause:3.10" as the CRI sandbox image.
[download-certs] Downloading the certificates in Secret "kubeadm-certs" in the "kube-system" Namespace
[download-certs] Saving the certificates to the folder: "/etc/kubernetes/pki"
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost node01] and IPs [172.30.11.11 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [localhost node01] and IPs [172.30.11.11 127.0.0.1 ::1]
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local node01] and IPs [10.96.0.1 172.30.11.11 172.30.11.19]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Valid certificates and keys now exist in "/etc/kubernetes/pki"
[certs] Using the existing "sa" key
[kubeconfig] Generating kubeconfig files
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[check-etcd] Checking that the etcd cluster is healthy
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-check] Waiting for a healthy kubelet at http://127.0.0.1:10248/healthz. This can take up to 4m0s
[kubelet-check] The kubelet is healthy after 1.529885559s
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap
[etcd] Announced new etcd member joining to the existing etcd cluster
[etcd] Creating static Pod manifest for "etcd"
{"level":"warn","ts":"2024-11-19T19:27:31.239596+0800","logger":"etcd-client","caller":"v3@v3.5.14/retry_interceptor.go:63","msg":"retrying of unary invoker failed","target":"etcd-endpoints://0xc0002ec1e0/172.30.11.10:2379","attempt":0,"error":"rpc error: code = FailedPrecondition desc = etcdserver: can only promote a learner member which is in sync with leader"}
[etcd] Waiting for the new etcd member to join the cluster. This can take up to 40s
[mark-control-plane] Marking the node node01 as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node node01 as control-plane by adding the taints [node-role.kubernetes.io/control-plane:NoSchedule]
This node has joined the cluster and a new control plane instance was created:
* Certificate signing request was sent to apiserver and approval was received.
* The Kubelet was informed of the new secure connection details.
* Control plane label and taint were applied to the new node.
* The Kubernetes control plane instances scaled up.
* A new etcd member was added to the local/stacked etcd cluster.
To start administering your cluster from this node, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Run 'kubectl get nodes' to see this node join the cluster.
[root@node01 ~]#
[root@node04 ~]# kubeadm join 172.30.11.19:6443 --token kihb7i.d90wk3t958pyli32 \
> --discovery-token-ca-cert-hash sha256:8f22e90937513ce622d54a865ee1debf41a0a253f40a79fe87ae395e5ee2a1b8
t@
[preflight] Running pre-flight checks
de
04
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-check] Waiting for a healthy kubelet at http://127.0.0.1:10248/healthz. This can take up to 4m0s
[kubelet-check] The kubelet is healthy after 2.523337137s
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap
This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
[root@node00 ~]# wget https://docs.projectcalico.org/manifests/calico.yaml
[root@node00 ~]# sed -i 's#docker.io/calico/#quay.io/calico/#g' calico.yaml
[root@node00 ~]# kubectl apply -f calico.yaml
[root@node00 ~]# wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/high-availability-1.21+.yaml
[root@node00 ~]# sed -i 's#registry.k8s.io/metrics-server#registry.cn-hangzhou.aliyuncs.com/google_containers#g' high-availability-1.21+.yaml
[root@node00 ~]# vim high-availability-1.21+.yaml # 在- args中 添加下行 禁用 TLS 证书验证
·······
- args:
······
- --kubelet-insecure-tls
······
[root@node00 ~]# kubectl apply -f high-availability-1.21+.yaml
# 重新生成token
[root@node00 ~]# kubeadm token create --print-join-command
kubeadm join 172.30.11.19:6443 --token e52zyt.r42ic6kw70th1rxi --discovery-token-ca-cert-hash sha256:8f22e90937513ce622d54a865ee1debf41a0a253f40a79fe87ae395e5ee2a1b8
# node节点执行 kubeadm join 172.30.11.19:6443 --token e52zyt.r42ic6kw70th1rxi --discovery-token-ca-cert-hash sha256:8f22e90937513ce622d54a865ee1debf41a0a253f40a79fe87ae395e5ee2a1b8
#重新生成certificate-key
#新版本命令 kubeadm init phase upload-certs --upload-certs
#旧版本命令 kubeadm init phase upload-certs --experimental-upload-certs
[root@node00 ~]# kubeadm init phase upload-certs --upload-certs
[upload-certs] Storing the certificates in Secret "kubeadm-certs" in the "kube-system" Namespace
[upload-certs] Using certificate key:
84b6e347bc7092b0a43e502fd8201bc2189a42c6da3a46e51672fc80e521517e
# master节点执行 kubeadm join 172.30.11.19:6443 --token e52zyt.r42ic6kw70th1rxi --discovery-token-ca-cert-hash sha256:8f22e90937513ce622d54a865ee1debf41a0a253f40a79fe87ae395e5ee2a1b8 --control-plane --certificate-key 84b6e347bc7092b0a43e502fd8201bc2189a42c6da3a46e51672fc80e521517e