1. <dd id="erndk"></dd>
                1. 純shell一鍵搭建k8s集群

                  互聯網 2022/4/30 7:13:25

                  部署環境:三臺centos7.9,其中一臺master節點,兩臺node節點 docker版本:20.10.14 kubernetes版本:1.23.6 master節點: [root@k8s-master ~]# cat deploy_k8s_master.sh #!/bin/bash#1.configure domain name resolveecho 192.168.121.50 k8s-master >>/etc/hos…

                  部署環境:三臺centos7.9,其中一臺master節點,兩臺node節點

                  docker版本:20.10.14

                  kubernetes版本:1.23.6

                   master節點:

                  [root@k8s-master ~]# cat deploy_k8s_master.sh
                  #!/bin/bash
                  #1.configure domain name resolve
                  echo '192.168.121.50 k8s-master' >>/etc/hosts
                  echo '192.168.121.51 k8s-node1' >>/etc/hosts
                  echo '192.168.121.52 k8s-node2' >>/etc/hosts
                  #2.close firewall
                  systemctl disable firewalld.service --now
                  #3.close selinux
                  sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
                  setenforce 0
                  #4.configure chrony
                  yum -y install chrony
                  sed -i -e 's/^server/#&/g' -e '2a server k8s-master iburst' /etc/chrony.conf
                  echo "allow all" >> /etc/chrony.conf
                  echo "local stratum 10" >> /etc/chrony.conf
                  #5.permanent close swap partition
                  sed -i 's/.*swap.*/#&/g' /etc/fstab
                  swapoff -a
                  #6.modify module parameter
                  modprobe br_netfilter
                  echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
                  echo "net.bridge.bridge-nf-call-ip6tables = 1" >> /etc/sysctl.conf
                  echo "net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.conf
                  sysctl -p
                  #7.install docker-ce
                  yum -y install yum-utils device-mapper-persistent-data lvm2
                  yum-config-manager --add-repo=yum-config-manager --add-repo=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7.9/x86_64/stable/
                  mv /etc/yum.repos.d/mirrors.tuna.tsinghua.edu.cn_docker-ce_linux_centos_7.9_x86_64_stable_.repo /etc/yum.repos.d/docker-ce.repo
                  echo 'gpgcheck=0' >>/etc/yum.repos.d/docker-ce.repo
                  yum -y install docker-ce docker-ce-cli containerd.io
                  systemctl enable docker --now
                  #8.configure docker image accelerator
                  tee /etc/docker/daemon.json <<-'EOF'
                  {
                  "insecure-registries" : ["0.0.0.0/0"],
                  "registry-mirrors": ["https://7o6gyryt.mirror.aliyuncs.com"],
                  "exec-opts": ["native.cgroupdriver=systemd"]
                  }
                  EOF
                  systemctl daemon-reload
                  systemctl restart docker
                  #9.configure k8s source and install k8s
                  cat >/etc/yum.repos.d/kubernetes.repo <<EOF
                  [kubernetes]
                  name=Kubernetes
                  baseurl=https://mirrors.tuna.tsinghua.edu.cn/kubernetes/yum/repos/kubernetes-el7-x86_64/
                  enabled=1
                  gpgcheck=0
                  EOF
                  yum install -y kubelet kubeadm kubectl
                  systemctl enable kubelet --now
                  #10.k8s-master initialization
                  version=$(kubelet --version |cut -d'v' -f2)
                  docker --version
                  kubelet --version
                  kubeadm init --kubernetes-version=${version} --apiserver-advertise-address=192.168.121.50 --image-repository registry.aliyuncs.com/google_containers --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16

                  --------------------------------------------------------------------------------------------------------------------------------------

                  node節點:

                  [root@k8s-node1 ~]# cat deploy_k8s_node.sh
                  #!/bin/bash
                  #1.configure domain name resolve
                  echo '192.168.121.50 k8s-master' >>/etc/hosts
                  echo '192.168.121.51 k8s-node1' >>/etc/hosts
                  echo '192.168.121.52 k8s-node2' >>/etc/hosts
                  #2.close firewall
                  systemctl disable firewalld.service --now
                  #3.close selinux
                  sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
                  setenforce 0
                  #4.configure chrony
                  yum -y install chrony
                  sed -i -e 's/^server/#&/g' -e '2a server k8s-master iburst' /etc/chrony.conf
                  chronyc sources
                  #5.permanent close swap partition
                  sed -i 's/.*swap.*/#&/g' /etc/fstab
                  swapoff -a
                  #6.modify module parameter
                  modprobe br_netfilter
                  echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
                  echo "net.bridge.bridge-nf-call-ip6tables = 1" >> /etc/sysctl.conf
                  echo "net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.conf
                  sysctl -p
                  #7.install docker-ce
                  yum -y install yum-utils device-mapper-persistent-data lvm2
                  yum-config-manager --add-repo=yum-config-manager --add-repo=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7.9/x86_64/stable/
                  mv /etc/yum.repos.d/mirrors.tuna.tsinghua.edu.cn_docker-ce_linux_centos_7.9_x86_64_stable_.repo /etc/yum.repos.d/docker-ce.repo
                  echo 'gpgcheck=0' >>/etc/yum.repos.d/docker-ce.repo
                  yum -y install docker-ce docker-ce-cli containerd.io
                  systemctl enable docker --now
                  #8.configure docker image accelerator
                  tee /etc/docker/daemon.json <<-'EOF'
                  {
                  "insecure-registries" : ["0.0.0.0/0"],
                  "registry-mirrors": ["https://7o6gyryt.mirror.aliyuncs.com"],
                  "exec-opts": ["native.cgroupdriver=systemd"]
                  }
                  EOF
                  systemctl daemon-reload
                  systemctl restart docker
                  #9.configure k8s source and install k8s
                  cat >/etc/yum.repos.d/kubernetes.repo <<EOF
                  [kubernetes]
                  name=Kubernetes
                  baseurl=https://mirrors.tuna.tsinghua.edu.cn/kubernetes/yum/repos/kubernetes-el7-x86_64/
                  enabled=1
                  gpgcheck=0
                  EOF
                  yum install -y kubelet kubeadm kubectl
                  systemctl enable kubelet --now
                  #10.check version
                  docker --version
                  kubelet --version

                  master節點腳本執行成功后,如下圖所示

                   然后將綠色框選中的部分在master節點執行,藍色框選中的部分在node節點執行

                  node節點加入master節點成功后如圖所示

                   然后我們在master節點上查看,此時狀態都是NotReady(master節點是因為缺少網絡插件,node節點是缺少網絡插件對應的鏡像和容器)

                   然后通過GitHub下載flannel插件

                  并安裝這個插件

                   安裝完插件之后,node節點就有了flannel插件相關的鏡像和容器,并且k8s集群的狀態都變成了Ready

                  隨時隨地學軟件編程-關注百度小程序和微信小程序
                  關于找一找教程網

                  本站文章僅代表作者觀點,不代表本站立場,所有文章非營利性免費分享。
                  本站提供了軟件編程、網站開發技術、服務器運維、人工智能等等IT技術文章,希望廣大程序員努力學習,讓我們用科技改變世界。
                  [純shell一鍵搭建k8s集群]http://www.yachtsalesaustralia.com/tech/detail-318203.html

                  贊(0)
                  關注微信小程序
                  程序員編程王-隨時隨地學編程

                  掃描二維碼或查找【程序員編程王】

                  可以隨時隨地學編程啦!

                  技術文章導航 更多>
                  掃一掃關注最新編程教程
                  国产在线拍揄自揄视频菠萝

                        1. <dd id="erndk"></dd>