k8s-1.24部署

1.24

containerd-1.6.4+k8s-1.24.0

rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-5.el7.elrepo.noarch.rpm

yum --enablerepo=elrepo-kernel install -y kernel-lt

grub2-set-default 0

master

touch master_containerd-1.6.4+k8s-1.24.0.sh

chmod +x master_containerd-1.6.4+k8s-1.24.0.sh

vim master_containerd-1.6.4+k8s-1.24.0.sh

#!/bin/bash

startTime=`date +%Y%m%d-%H:%M:%S`
startTime_s=`date +%s`
#1、环境准备

#设置主机名
#hostnamectl set-hostname master

#添加hosts解析
#cat >> /etc/hosts << EOF
#192.168.1.201 master
#192.168.1.202 node1
#192.168.1.203 node2
#EOF

ping -c2 master
ping -c2 node1
ping -c2 node2

#同步时间
yum -y install ntp

systemctl start ntpd && systemctl enable ntpd && systemctl status ntpd

#关闭防火墙
systemctl stop firewalld && systemctl disable firewalld && systemctl status firewalld

#永久关闭seLinux(需重启系统生效)
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

#关闭swap
swapoff -a  # 临时关闭
sed -i 's/.*swap.*/#&/g' /etc/fstab

#加载IPVS模块
yum -y install ipset ipvsadm

cat > /etc/sysconfig/modules/ipvs.modules <<EOF
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
EOF

kernel_version=$(uname -r | cut -d- -f1)
echo $kernel_version

if [ `expr $kernel_version \> 4.19` -eq 1 ]
    then
        modprobe -- nf_conntrack
    else
        modprobe -- nf_conntrack_ipv4
fi

chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack

#2、部署Containerd
cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF

# 1.20+需要开启br_netfilter
sudo modprobe overlay
sudo modprobe br_netfilter

cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables  = 1
net.ipv4.ip_forward                 = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF

sudo sysctl --system

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

yum list |grep containerd

yum -y install containerd.io-1.6.4-3.1.el7.x86_64

mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml

# 修改cgroup Driver为systemd
sed -ri 's#SystemdCgroup = false#SystemdCgroup = true#' /etc/containerd/config.toml

# 更改sandbox_image
sed -ri 's#k8s.gcr.io\/pause:3.6#registry.aliyuncs.com\/google_containers\/pause:3.7#' /etc/containerd/config.toml

# endpoint位置添加阿里云的镜像源
sed -ri 's#https:\/\/registry-1.docker.io#https:\/\/registry.aliyuncs.com#' /etc/containerd/config.toml

systemctl daemon-reload

systemctl enable containerd --now

systemctl status containerd

#3、Kubernetes部署
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
EOF

yum list kubeadm --showduplicates | sort -r

yum -y install kubeadm-1.24.0-0 kubelet-1.24.0-0 kubectl-1.24.0-0

systemctl enable --now kubelet

systemctl status kubelet

#设置crictl
cat << EOF >> /etc/crictl.yaml
runtime-endpoint: unix:///var/run/containerd/containerd.sock
image-endpoint: unix:///var/run/containerd/containerd.sock
timeout: 10 
debug: false
EOF

mkdir ~/kubeadm_init && cd ~/kubeadm_init

kubeadm config print init-defaults > kubeadm-init.yaml

cat > kubeadm-init.yaml << EOF
apiVersion: kubeadm.k8s.io/v1beta3
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: `hostname -i`  #master_ip
  bindPort: 6443
nodeRegistration:
  criSocket: unix:///var/run/containerd/containerd.sock
  imagePullPolicy: IfNotPresent
  name: master
  taints:
  - effect: "NoSchedule"
    key: "node-role.kubernetes.io/master"
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns: {}
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: registry.aliyuncs.com/google_containers
kind: ClusterConfiguration
kubernetesVersion: v1.24.0
networking:
  dnsDomain: cluster.local
  serviceSubnet: 10.96.0.0/12
  podSubnet: 10.244.0.0/16
scheduler: {}
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: systemd
EOF

# 查看所需镜像列表
kubeadm config images list --config kubeadm-init.yaml

# 预拉取镜像
kubeadm config images pull --config kubeadm-init.yaml

ctr -n k8s.io i ls -q

crictl images

crictl ps -a

kubeadm init --config=kubeadm-init.yaml | tee kubeadm-init.log

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

kubectl get node -owide 
endTime=`date +%Y%m%d-%H:%M:%S`
endTime_s=`date +%s`

sumTime=$[ $endTime_s - $startTime_s ]

echo "$startTime ---> $endTime" "Total:$sumTime seconds"

node

touch node_containerd-1.6.4+k8s-1.23.1.sh

chmod +x node_containerd-1.6.4+k8s-1.23.1.sh

vim node_containerd-1.6.4+k8s-1.23.1.sh

#!/bin/bash

startTime=`date +%Y%m%d-%H:%M:%S`
startTime_s=`date +%s`
#1、环境准备

#设置主机名
#hostnamectl set-hostname node

#添加hosts解析
#cat >> /etc/hosts << EOF
#192.168.1.201 master
#192.168.1.202 node1
#192.168.1.203 node2
#EOF

ping -c2 master
ping -c2 node1
ping -c2 node2

#同步时间
yum -y install ntp

systemctl start ntpd && systemctl enable ntpd && systemctl status ntpd

#关闭防火墙
systemctl stop firewalld && systemctl disable firewalld && systemctl status firewalld

#永久关闭seLinux(需重启系统生效)
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

#关闭swap
swapoff -a  # 临时关闭
sed -i 's/.*swap.*/#&/g' /etc/fstab

#加载IPVS模块
yum -y install ipset ipvsadm

cat > /etc/sysconfig/modules/ipvs.modules <<EOF
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
EOF

kernel_version=$(uname -r | cut -d- -f1)
echo $kernel_version

if [ `expr $kernel_version \> 4.19` -eq 1 ]
    then
        modprobe -- nf_conntrack
    else
        modprobe -- nf_conntrack_ipv4
fi

chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack

#2、部署Containerd
cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables  = 1
net.ipv4.ip_forward                 = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF

sudo sysctl --system

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

yum list |grep containerd

yum -y install containerd.io-1.6.4-3.1.el7.x86_64
mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml

# 修改cgroup Driver为systemd
sed -ri 's#SystemdCgroup = false#SystemdCgroup = true#' /etc/containerd/config.toml

# 更改sandbox_image
sed -ri 's#k8s.gcr.io\/pause:3.6#registry.aliyuncs.com\/google_containers\/pause:3.7#' /etc/containerd/config.toml

# endpoint位置添加阿里云的镜像源
sed -ri 's#https:\/\/registry-1.docker.io#https:\/\/registry.aliyuncs.com#' /etc/containerd/config.toml

systemctl daemon-reload

systemctl enable containerd --now

systemctl status containerd

#3、Kubernetes部署
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
EOF

yum list kubeadm --showduplicates | sort -r

yum -y install kubeadm-1.24.0-0 kubelet-1.24.0-0 kubectl-1.24.0-0

systemctl enable --now kubelet

systemctl status kubelet

#设置crictl
cat << EOF >> /etc/crictl.yaml
runtime-endpoint: unix:///var/run/containerd/containerd.sock
image-endpoint: unix:///var/run/containerd/containerd.sock
timeout: 10 
debug: false
EOF

# 预拉取镜像
crictl pull registry.aliyuncs.com/google_containers/kube-proxy:v1.24.0
crictl pull registry.aliyuncs.com/google_containers/pause:3.7

ctr -n k8s.io i ls -q

crictl images

crictl ps -a

rm -rf ~/kubeadm_init

endTime=`date +%Y%m%d-%H:%M:%S`
endTime_s=`date +%s`

sumTime=$[ $endTime_s - $startTime_s ]

echo "$startTime ---> $endTime" "Total:$sumTime seconds"

calico

curl https://docs.projectcalico.org/manifests/calico.yaml -O

kubectl apply -f calico.yaml
posted @ 2022-06-16 17:43  Linux-k8s开发  阅读(773)  评论(0)    收藏  举报