K8S集群部署--亲测好用

news/2025/2/3 11:39:27 标签: kubernetes, java, linux

最近在自学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 << EOF

192.168.206.130 k8s-node2
192.168.206.131 k8s-node1
192.168.206.132 k8s-master
EOF
  • Modify machine kernel parameters
    • modprobe br_netfilter
      
      echo "modprobe br_netfilter" >> /etc/profile
      
      cat > /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
      EOF
      
      sysctl -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/.kube

  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.

Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:

  Installing Addons | Kubernetes

Then 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 Agent

   Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)

  Drop-In: /usr/lib/systemd/system/kubelet.service.d

           └─10-kubeadm.conf

   Active: active (running) since Fri 2025-01-31 15:39:18 CST; 3min 41s ago

     Docs: Kubernetes Documentation | Kubernetes

 Main PID: 15836 (kubelet)

    Tasks: 15

   Memory: 36.9M

   CGroup: /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/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo 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 nodes

NAME          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.niftyadmin.cn/n/5840755.html

相关文章

【Rust自学】19.2. 高级trait:关联类型、默认泛型参数和运算符重载、完全限定语法、supertrait和newtype

喜欢的话别忘了点赞、收藏加关注哦&#xff08;加关注即可阅读全文&#xff09;&#xff0c;对接下来的教程有兴趣的可以关注专栏。谢谢喵&#xff01;(&#xff65;ω&#xff65;) 19.2.1. 在trait定义中使用关联类型来指定占位类型 我们首先在第10章的10.3. trait Pt.1&a…

用结构加法3ax+1预测第4点的分布

有1个点在19*19的平面上在某种力的作用下运动&#xff0c;轨迹为 共移动了90步&#xff0c;按照&#xff08;0&#xff0c;1&#xff0c;2&#xff0c;3&#xff09;&#xff0c;&#xff08;1&#xff0c;2&#xff0c;3&#xff0c;4&#xff09;&#xff0c;…&#xff0c;&…

【最长上升子序列Ⅱ——树状数组,二分+DP,纯DP】

题目 代码&#xff08;只给出树状数组的&#xff09; #include <bits/stdc.h> using namespace std; const int N 1e510; int n, m; int a[N], b[N], f[N], tr[N]; //f[i]表示以a[i]为尾的LIS的最大长度 void init() {sort(b1, bn1);m unique(b1, bn1) - b - 1;for(in…

玩转Docker | 使用Docker部署SSCMS内容管理系统

玩转Docker | 使用Docker部署SSCMS内容管理系统 前言一、项目介绍SSCMS 简介主要特点二、系统要求环境要求环境检查Docker版本检查检查操作系统版本三、部署SSCMS系统下载镜像创建容器检查容器状态检查服务端口安全设置四、访问SSCMS应用初始化配置访问SSCMS管理后台六、配置SS…

课题介绍:基于惯性与单目视觉信息融合的室内微小型飞行器智能自主导航研究

室内微小型飞行器在国防、物流和监测等领域中应用广泛&#xff0c;但在复杂的非合作环境中实时避障和导航仍面临诸多挑战。由于微小型飞行器的载荷和能源限制&#xff0c;迫切需要开发高效的智能自主导航系统。本项目旨在研究基于惯性导航与单目视觉信息融合的技术&#xff0c;…

Python-基于PyQt5,pdf2docx,pathlib的PDF转Word工具(专业版)

前言:日常生活中,我们常常会跟WPS Office打交道。作表格,写报告,写PPT......可以说,我们的生活已经离不开WPS Office了。与此同时,我们在这个过程中也会遇到各种各样的技术阻碍,例如部分软件的PDF转Word需要收取额外费用等。那么,可不可以自己开发一个小工具来实现PDF转…

SAP SD学习笔记28 - 请求计划(开票计划)之2 - Milestone请求(里程碑开票)

上一章讲了请求计划&#xff08;开票计划&#xff09;中的 定期请求。 SAP SD学习笔记27 - 请求计划(开票计划)之1 - 定期请求-CSDN博客 本章继续来讲请求计划&#xff08;开票计划&#xff09;的其他内容&#xff1a; Milestone请求(里程碑请求)。 目录 1&#xff0c;Miles…

鸿蒙 组件封装使用

效果 项目目录截图 一、GoodItem代码如下 import { Item } from ../entity/Item/*** GoodItem 组件用于展示商品信息* 它包含商品的图片、名称、价格和优惠信息*/ Component export struct GoodItem {// 商品项&#xff0c;包含商品的基本信息public goodsItem: Item new Item…