centos7.9安装kubernetes1.27.4版本

#安装kubernetes1.27.4版本
#关闭swap
swapoff -a
sed -i '/swap/s/^/#/' /etc/fstab

#关闭防火墙
systemctl disable --now firewalld

#时间同步
yum -y install ntpdate
ntpdate time2.aliyun.com
# 加入到crontab
*/5 * * * * /usr/sbin/ntpdate time2.aliyun.com

#修改主机名
hostnamectl set-hostname k8s-master01 && bash
hostnamectl set-hostname k8s-node01 && bash
hostnamectl set-hostname k8s-node02 && bash

cat <<EOF >> /etc/hosts
10.0.0.21 k8s-master01
10.0.0.22 k8s-node01
10.0.0.23 k8s-node02

EOF


#修改Linux内核参数,添加网桥过滤器和地址转发功能
cat >> /etc/sysctl.d/kubernetes.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF


modprobe br_netfilter
sysctl -p /etc/sysctl.d/kubernetes.conf


#配置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
modprobe -- nf_conntrack_ipv4  
EOF
chmod +x /etc/sysconfig/modules/ipvs.modules
/etc/sysconfig/modules/ipvs.modules


#安装Docker容器
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache
yum install -y yum-utils


yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce-20.10.6 docker-ce-cli-20.10.6 -y
mkdir /etc/docker

cat <<EOF > /etc/docker/daemon.json
{
"registry-mirrors": [
 "https://docker.mirrors.ustc.edu.cn",
 "https://hub-mirror.c.163.com",
 "https://reg-mirror.qiniu.com",
 "https://registry.docker-cn.com"
],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "200m"
},
"storage-driver": "overlay2"
}
EOF
systemctl enable --now docker




#安装cri-dockerd-0.3.1插件

wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.1/cri-dockerd-0.3.1-3.el7.x86_64.rpm

rpm -ivh cri-dockerd-0.3.1-3.el7.x86_64.rpm

sed -i "s/^ExecStart/#&/" /usr/lib/systemd/system/cri-docker.service
sed -i '10iExecStart=/usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.7' /usr/lib/systemd/system/cri-docker.service

systemctl daemon-reload && systemctl restart docker cri-docker.socket cri-docker





#配置国内yum源,安装 kubeadm、kubelet、kubectl
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=0
EOF


yum install -y kubelet-1.27.4 kubeadm-1.27.4 kubectl-1.27.4
systemctl enable kubelet.service --now




#安装runc-1.1.10

wget https://github.com/opencontainers/runc/releases/download/v1.1.10/runc.amd64


sudo install -m 755 runc.amd64  /usr/local/bin/runc
runc -v


#初始化
kubeadm init --node-name=k8s-master01 --image-repository=registry.aliyuncs.com/google_containers --cri-socket=unix:///var/run/cri-dockerd.sock --apiserver-advertise-address=10.0.0.21 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12

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


#不做的话后面网络插件部署不起啦
scp /etc/kubernetes/admin.conf 10.0.0.23:/etc/kubernetes/
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >>  ~/.bash_profile
source ~/.bash_profile

#部署flannel
wget https://github.com/flannel-io/flannel/releases/download/v0.22.0/kube-flannel.yml
kubectl apply -f kube-flannel.yml

posted @ 2023-11-09 21:49  GlassHeart  阅读(111)  评论(0)    收藏  举报