K8S集群部署--亲测好用

devtools/2025/2/3 14:42:47/

最近在自学K8S,花了三天最后终于成功部署一套K8S Cluster集群(master+node1+node2)

在这里先分享一下具体的步骤,后续再更新其他的内容:例如部署期间遇到的问题及其解决办法。

部署步骤是英文写的,最近想练练英文,所以就这样了,但是都比较基础的英文,都能看懂:

1.Preparing 3 servers like below: My lab is Centos 7

Master Node:

  • Disabled the Firewall and SE Linux:
    systemctl disable firewalld
    sed -i '/selinux/enforcing/disabled/' /etc/selinux/config
  • Disable swap(Remember to restart the VM):
    • swapoff -a  ##This is the temporary way
      #swap options under the path of /etc/fstab  ##permernent way
  • Change hostname:
    • hostnamectl set-hostname k8s-master
  • Add the hostname to the /etc/hosts
cat >> /etc/hosts << EOF192.168.206.130 k8s-node2
192.168.206.131 k8s-node1
192.168.206.132 k8s-master
EOF
  • Modify machine kernel parameters
    • modprobe br_netfilterecho "modprobe br_netfilter" >> /etc/profilecat > /etc/sysctl.d/k8s.conf <<EOF
      net.bridge.bridge-nf-call-ip6tables = 1
      net.bridge.bridge-nf-call-iptables = 1
      net.ipv4.ip_forward = 1
      EOFsysctl -p /etc/sysctl.d/k8s.conf
  • Config the yum:
[root@k8s-master1 yum.repos.d]# cat kubernetes.repo[kubernetes]name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0[root@k8s-master1 yum.repos.d]# cat docker-ce.repo[docker-ce-stable]name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-stable-debuginfo]name=Docker CE Stable - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-stable-source]name=Docker CE Stable - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-test]name=Docker CE Test - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-test-debuginfo]name=Docker CE Test - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-test-source]name=Docker CE Test - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-nightly]name=Docker CE Nightly - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-nightly-debuginfo]name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg[docker-ce-nightly-source]name=Docker CE Nightly - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  • Install the docker and enable it:
    • yum install -y docker-ce docker-ce-cli containerd.io
      systemctl enable docker && systemctl start docker
      docker --version
  • Configure the docker speeder and driver:
vi /etc/docker/daemon.json
{"exec-opts": ["native.cgroupdriver=systemd"],         
"registry-mirrors": ["https://tl522tpb.mirror.aliyuncs.com","https://docker.m.daocloud.io/","https://huecker.io/","https://dockerhub.timeweb.cloud","https://noohub.ru/","https://dockerproxy.com","https://docker.mirrors.ustc.edu.cn","https://docker.nju.edu.cn","https://xx4bwyg2.mirror.aliyuncs.com","http://f1361db2.m.daocloud.io","https://registry.docker-cn.com","http://hub-mirror.c.163.com"]}
  • Reload the json file and restart the docker service :
    • systemctl daemon-reload && systemctl restart docker
      systemctl status docker
  • Install the NTP and update the time:
    • yum install ntpdate -y
      ntpdate time.windows.com
  • Install the K8S
    • yum install -y kubelet-1.23.6 kubeadm-1.23.6 kubectl-1.23.6
      systemctl enable kubelet
  • Init the Master : ##You need to edit IP information on your system
kubeadm init \--kubernetes-version=v1.23.6 \--apiserver-advertise-address=192.168.206.132 \--image-repository=registry.aliyuncs.com/google_containers \--service-cidr=192.168.204.0/24 \--pod-network-cidr=192.168.159.0/24

If the init option can be ran successfully, you will see the below words:

​Your Kubernetes control-plane has initialized successfully!To start using your cluster, you need to run the following as a regular user:mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, if you are the root user, you can run:export KUBECONFIG=/etc/kubernetes/admin.confYou should now deploy a pod network to the cluster.Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:Installing Addons | KubernetesThen you can join any number of worker nodes by running the following on each as root:kubeadm join 192.168.206.132:6443 --token 8he0uh.8ftagcf7yk0ccy0j \--discovery-token-ca-cert-hash sha256:5a97b36bed5a4e31d2ae08f7efd0a4a62b6d08ae63f9341f889b92601716b827
​
  • Check the Kubelet service status:
​
[root@k8s-master1 ~]# systemctl status kubelet.service● kubelet.service - kubelet: The Kubernetes Node AgentLoaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)Drop-In: /usr/lib/systemd/system/kubelet.service.d└─10-kubeadm.confActive: active (running) since Fri 2025-01-31 15:39:18 CST; 3min 41s agoDocs: Kubernetes Documentation | KubernetesMain PID: 15836 (kubelet)Tasks: 15Memory: 36.9MCGroup: /system.slice/kubelet.service└─15836 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --conf...Jan 31 15:42:39 k8s-master1 kubelet[15836]: I0131 15:42:39.171118   15836 cni.go:240] "Unable to update cni config" err="no networks found...i/net.d"
​

Configure the enviroment:

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

The master node has completed.

For the Node deploy please flow the steps :

  • Disabled the Firewall and SE Linux:
  • Disable swap(Remember to restart the VM):
  • Change hostname: k8s-node1,etc
  • Add the hostname to the /etc/hosts
  • Modify machine kernel parameters
  • Config the yum
  • Install the docker and enable it
  • Configure the docker speeder and driver
  • Reload the json file
  • Install the NTP and update the time
  • Install the K8S

Add nodes to the master:

kubeadm join 192.168.206.132:6443 --token 8he0uh.8ftagcf7yk0ccy0j --discovery-token-ca-cert-hash sha256:5a97b36bed5a4e31d2ae08f7efd0a4a62b6d08ae63f9341f889b92601716b827

Check the nodes:

[root@k8s-master1 yum.repos.d]# kubectl get nodesNAME          STATUS   ROLES                  AGE    VERSION
k8s-master1   NotReady    control-plane,master   2d2h   v1.23.6
k8s-node1     NotReady    <none>                 46h    v1.23.6
k8s-node2     NotReady    <none>                 45h    v1.23.6

Add the CNI network add-in:

Create folder :mkdir ~./k8s

Download the yaml file

  • curl https://calico-v3-25.netlify.app/archive/v3.25/manifests/calico.yaml -O
    ​kubectl apply -f yaml
  • You also can download the yaml file from this command and apply it:
kubectl apply -f https://calico-v3-25.netlify.app/archive/v3.25/manifests/calico.yaml
​

Short the containers:

  • sed -i 's#docker.io/##g' calico.yaml

Check the Pod status:

 kubectl get po -n kube-system -o wide

If display like below will be good for the containers: Pod Status all Running and Ready

Check the node status:

 kubectl get nodes


http://www.ppmy.cn/devtools/155741.html

相关文章

代码讲解系列-CV(一)——CV基础框架

文章目录 一、环境配置IDE选择一套完整复现安装自定义cuda算子 二、Linux基础文件和目录操作查看显卡状态压缩和解压 三、常用工具和pipeline远程文件工具版本管理代码辅助工具 随手记录下一个晚课 一、环境配置 pytorch是AI框架用的很多&#xff0c;或者 其他是国内的框架 an…

[c语言日寄]越界访问:意外的死循环

【作者主页】siy2333 【专栏介绍】⌈c语言日寄⌋&#xff1a;这是一个专注于C语言刷题的专栏&#xff0c;精选题目&#xff0c;搭配详细题解、拓展算法。从基础语法到复杂算法&#xff0c;题目涉及的知识点全面覆盖&#xff0c;助力你系统提升。无论你是初学者&#xff0c;还是…

x86-64数据传输指令

关于汇编语言一些基础概念的更详细的介绍&#xff0c;可移步MIPS指令集&#xff08;一&#xff09;基本操作_mips指令 sw-CSDN博客 该指令集中一个字2字节。 该架构有16个64位寄存器&#xff0c;名字都以%r开头&#xff0c;每个寄存器的最低位字节&#xff0c;低1~2位字节&…

golang通过AutoMigrate方法自动创建table详解

一.AutoMigrate介绍 1.介绍 在 Go 语言中&#xff0c;GORM支持Migration特性&#xff0c;支持根据Go Struct结构自动生成对应的表结构,使用 GORM ORM 库的 AutoMigrate 方法可以自动创建数据库表&#xff0c;确保数据库结构与定义的模型结构一致。AutoMigrate 方法非常方便&am…

C# 小说阅读 文本文件阅读

小说阅读 文本文件阅读 编程语言&#xff1a;C# 目录页 阅读 浏览页(webBrowser)&#xff1a;

【JavaEE】_MVC架构与三层架构

目录 1. MVC架构 2. 三层架构 3. MVC架构与三层架构的对比 3.1 MVC与三层架构的对比 3.2 MVC与三层架构的共性 1. MVC架构 在前文已介绍关于SpringMAC的设计模式&#xff0c;详见下文&#xff1a; 【JavaEE】_Spring Web MVC简介-CSDN博客文章浏览阅读967次&#xff0c;点…

【数据分析】案例03:当当网近30日热销图书的数据采集与可视化分析(scrapy+openpyxl+matplotlib)

当当网近30日热销图书的数据采集与可视化分析(scrapy+openpyxl+matplotlib) 当当网近30日热销书籍官网写在前面 实验目的:实现当当网近30日热销图书的数据采集与可视化分析。 电脑系统:Windows 使用软件:Visual Studio Code Python版本:python 3.12.4 技术需求:scrapy、…

【数据分享】1929-2024年全球站点的逐月平均能见度(Shp\Excel\免费获取)

气象数据是在各项研究中都经常使用的数据&#xff0c;气象指标包括气温、风速、降水、湿度等指标&#xff01;说到气象数据&#xff0c;最详细的气象数据是具体到气象监测站点的数据&#xff01; 有关气象指标的监测站点数据&#xff0c;之前我们分享过1929-2024年全球气象站点…