Kubernetes 1.23 版本kubeadm 安装部署

安装环境

 

安装步骤

PS 下面步骤在master 和 worker 节点都需要执行

1、修改主机名

hostnamectl set-hostname master-01

cat >> /etc/hosts << EOF
172.28.32.1   master-01
172.28.32.2   worker-01
EOF

 

2、配置Centos 7.9 阿里云官方源

mkdir -p /etc/yum.repos.d/back
find /etc/yum.repos.d/ -type f -exec mv {} /etc/yum.repos.d/back/ \;
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

 

3、关闭firewalld

systemctl stop firewalld.service
systemctl disable firewalld.service

 

4、关闭交换分区及selinux

sed -i.bak '/swap/s/^/#/' /etc/fstab
sed -i 's/^ *SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

 

5、配置内核转发等相关参数

modprobe br_netfilter

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

cat << EOF >> /etc/sysctl.conf
net.ipv4.ip_forward=1
EOF

chmod a+x /etc/rc.local
echo "source /etc/profile" >> /etc/rc.local
echo "modprobe br_netfilter" >> /etc/rc.local
echo "sysctl -p /etc/sysctl.d/k8s.conf" >> /etc/rc.local
echo "sysctl -p" >> //etc/rc.local

reboot    # 重启时因为需要重新检测selinux 的策略

 

6、安装docker

yum -y install wget yum-utils device-mapper-persistent-data lvm2

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

yum list docker-ce --showduplicates | sort -r
yum remove docker-ce docker-ce-cli containerd.io
yum install -y docker-ce-20.10.8 docker-ce-cli-20.10.8 containerd.io

systemctl enable docker --now


# 这里设置cgroup 的类型为 systemd
cat > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": ["https://2ywfua5b.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF

systemctl daemon-reload
systemctl restart docker

 

7、安装kubelet、kubeadm、kubectl

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/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

yum remove kubeadm kubectl kubelet kubernetes-cni cri-tools socat
yum --showduplicates list kubeadm
yum -y install kubeadm-1.23.8 kubectl-1.23.8 kubelet-1.23.8
systemctl enable kubelet

 

8、kubeadm 初始化集群

PS: 仅限MASTER 节点执行

PS: 下面操作是用来做init 之前预先拉取镜像操作, 但是个人测试这个方法并不如init 时指定的 --image-repository  好用
kubeadm config images list

#!/bin/bash
url=registry.cn-hangzhou.aliyuncs.com/google_containers
# 安装指定的kubectl版本, 这里的版本以实际 kubeadm config images list 显示的版本为准
version=v1.23.9
# 上面查出来的coredns版本号
coredns=v1.8.6
images=(`kubeadm config images list --kubernetes-version=$version|awk -F '/' '{print $2}'`)
for imagename in ${images[@]} ; do
   if [ $imagename = "coredns" ]
   then
      docker pull $url/coredns:$coredns
      docker tag $url/coredns:$coredns k8s.gcr.io/coredns/coredns:$coredns
      docker rmi -f $url/coredns:$coredns
   else
      docker pull $url/$imagename
      docker tag $url/$imagename k8s.gcr.io/$imagename
      docker rmi -f $url/$imagename
  fi
done

docker images 
可选操作
kubeadm init --kubernetes-version=1.23.8 --apiserver-advertise-address=172.28.32.1 --pod-network-cidr=10.244.0.0/16 --image-repository registry.aliyuncs.com/google_containers

 

9、对集群做config 认证

PS: 仅限MASTER 节点执行

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

 

10、worker 节点加入集群

PS: 仅限WORKER节点执行

kubeadm join 172.28.32.1:6443 --token i2meul.73ipaykm3jc2k6vs --discovery-token-ca-cert-hash sha256:9e6d95ffc5ba78a5c71352ffcc9bca2330b17264ebc44facf6359b1ac153f33f

 

11、安装网络组件请参考此文档

PS: 仅限MASTER 节点执行

https://v1-23.docs.kubernetes.io/zh/docs/concepts/cluster-administration/networking/#flannel

 

posted @ 2022-07-16 16:00  寻真丶  阅读(503)  评论(0编辑  收藏  举报