当前位置: 首页 > article >正文

K8S集群部署--亲测好用

最近在自学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.kler.cn/a/531542.html

相关文章:

  • Kamailio 不通过 dmq 实现注册复制功能
  • 【C++】继承(下)
  • 2.3学习总结
  • 使用 Elastic Cloud Hosted 优化长期数据保留:确保政府合规性和效率
  • 解析 Oracle 中的 ALL_SYNONYMS 和 ALL_VIEWS 视图:查找同义词与视图的基础操作
  • Vue3 表单:全面解析与最佳实践
  • 使用 Elastic Cloud Hosted 优化长期数据保留:确保政府合规性和效率
  • 33.Word:国家中长期人才发展规划纲要【33】
  • Turing Complete-全加器
  • 使用 Grafana 和 Prometheus展现消息队列性能
  • 【Elasticsearch】硬件资源优化
  • 解锁数据结构密码:层次树与自引用树的设计艺术与API实践
  • FFmpeg:多媒体处理的瑞士军刀
  • Android 深入探究 JSONObject 与 JSONArray:Android 中的数据解析与数组操作全解析
  • 快速提升网站收录:利用网站新闻发布功能
  • 弹性力学部分
  • selenium记录Spiderbuf例题C02
  • 神经网络参数量和运算量的计算- 基于deepspeed库和thop库函数
  • 论文paper(更新...)
  • Apache Hudi数据湖技术应用在网络打车系统中的系统架构设计、软硬件配置、软件技术栈、具体实现流程和关键代码
  • P7497 四方喝彩 Solution
  • Linux+Docer 容器化部署之 Shell 语法入门篇 【Shell 循环类型】
  • Ollama教程:轻松上手本地大语言模型部署
  • linux库函数 gettimeofday() localtime的概念和使用案例
  • kamailio源文件modules.lst的内容解释
  • 通信方式、点对点通信、集合通信