centos8-k8s-1.25安装步骤

2023-04-06

准备6台主机,3master 3worker,安装docker-ce

1、安装系统初始化
yum update
yum -y install perl gcc gcc-c++ cpp bzip2 openssl-devel bind-utils wget net-tools nmon iftop readline readline-devel
1)、swapoff -a

2)、setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

3)、chrony sources -v
4)、timedatectl set-timezone Asia/Shanghai
ls -l /etc/localtime

2、时间同步,修改hosts
#!/bin/sh

systemctl stop firewalld && systemctl disable firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
setenforce 0

yum -y install chrony

sed -i 's/2.centos.pool.ntp.org/ntp3.aliyun.com/g' /etc/chrony.conf
sed -i 's/#local/local/g' /etc/chrony.conf
sed -i "/#allow/a allow all" /etc/chrony.conf

systemctl enable chronyd.service
systemctl restart chronyd.service
chronyc sources -v;date

3、关闭防火墙/setenforce 0
4、sysctl.d/k8s.conf和/etc/modules-load.d/ipvs.conf
5、每台都需要安装docker-ce/cri-dockerd或者/containerd/非常重要
docker -v
6、每台都需要安装docker-ce和kubelet-kubeadm-kubectl,最新1.25.0,并systemctl enable --now kubelet
7、docker pull images
tag改标签

8、kubeadm init --cri-socket unix:///var/run/cri-dockerd.socket
kubeadm reset --cri-socket unix:///var/run/cri-dockerd.sock
kubeadm join --cri-socket unix:///var/run/cri-dockerd.socket

9、kalico和flannel网络
10、dashboard,获取token
###########################
4、k8s需要配置
#!/bin/sh

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

vm.swappiness=0
vm.overcommit_memory=1
vm.panic_on_oom=0

fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
fs.may_detach_mounts = 1
net.netfilter.nf_conntrack_max=2310720

net.core.somaxconn = 16384
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_orphan_retries = 3
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl =15
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.tcp_max_orphans = 327680
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.ip_conntrack_max = 65536
net.ipv4.tcp_max_syn_backlog = 16384

net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.conf.lo.disable_ipv6 = 0
net.ipv6.conf.all.forwarding = 1
EOF

sysctl -p /etc/sysctl.d/k8s.conf

yum -y install ipvsadm ipset sysstat conntrack libseccomp

sysctl --system

modprobe br_netfilter
cat > /etc/sysconfig/modules/ipvs.modules < /etc/modules-load.d/ipvs.conf
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack
ip_tables
ip_set
xt_set
ipt_set
ipt_rpfilter
ipt_REJECT
ipip
EOF
systemctl restart systemd-modules-load.service
lsmod | grep -e ip_vs -e nf_conntrack

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

ver=1.25.3
yum -y install kubeadm-${ver} kubectl-${ver} kubelet-${ver}

cat << EOF > ~/restart_kubelet.sh
systemctl enable --now kubelet
EOF

echo 'source <(kubectl completion bash)' >> ~/.bash_profile

8、初始化
#kubeadm init --apiserver-advertise-address=10.28.29.151 --image-repository registry.aliyuncs.com/google_containers --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16

ver=v1.25.0

kubeadm init \
--apiserver-advertise-address=172.16.71.11 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version=$ver \
--pod-network-cidr=10.244.0.0/16 \
--ignore-preflight-errors=Swap \
--cri-socket unix:///var/run/cri-dockerd.sock \
--v=5 |tee init.out

kubectl -n kube-system edit cm kubeadm-config
kubernetesVersion: 1.25.0
controlPlaneEndpoint: "172.16.71.11:6443" 添加

cd /etc/kubernetes
zip -r pki.zip admin.conf pki/ca* pki/front-proxy-c* pki/sa* pki/etcd/ca.*
复制到其他master节点初始化

9、报错后重新搞
使用journalctl -xeu kubelet发现因为无法拉取k8s.gcr.io/pause:3.6导致pod创建失败
通过查文档,发现containerd默认配置中用到了该镜像,通过覆盖默认生成的文件,并重启containerd解决。

systemctl restart containerd

清理集群,重新初始化

kubeadm reset --cert-dir /etc/kubernetes/pki
10、join master2

unable to add a new control plane instance to a cluster that doesn't have a stable controlPlaneEndpoint address

添加controlPlaneEndpoint这个参数

# kubectl edit cm kubeadm-config -n kube-system
kubernetesVersion: v1.25.3
controlPlaneEndpoint: 10.28.28.101:6443
复制/etc/pki/ca.crt

Join
kubeadm join 10.28.28.101:6443 --token il3ox8.7yml00p14zpzhv4m \
--discovery-token-ca-cert-hash sha256:3843f3c22af462d577e6ad4d8cb87810fd90452934991972df81e33bbf43a94e \
--control-plane \
--cri-socket unix:///var/run/containerd/containerd.sock \
--v=5 |tee init.out

KUBELET_EXTRA_ARGS=--node-ip=10.10.10.102 --cgroup-driver=cgroupfs

11、join worker节点
kubeadm token list
#token如果没有就是过期了 要重新生成
vgih4q.i9fdwn0mjwa67r7n

kubeadm token create

openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'

932e86d9ca1a7444f9de70272a614271c93deacbd053c404743f637f8e669514

kubeadm join 127.0.0.1:8443 --token vgih4q.i9fdwn0mjwa67r7n \
--discovery-token-ca-cert-hash sha256:932e86d9ca1a7444f9de70272a614271c93deacbd053c404743f637f8e669514 \
--v=5

kubeadm config images list

12、污点处理
1)、让 master节点参与POD负载的命令为
kubectl taint nodes --all node-role.kubernetes.io/master-

2)、让 master节点恢复不参与POD负载的命令为
kubectl taint nodes node-role.kubernetes.io/master=:NoSchedule

参考文档:
https://kubernetes.io/docs/home/
https://kubernetes.io/zh-cn/docs/home/

分类:Linux | 标签: |

相关日志

评论被关闭!