Yum 部署K8S集群

news/2024/11/8 19:57:55/

目录

1、准备环境 (温馨提示:尽量一次完成集群)

2.安装master节点

3、安装k8s-master上的node

4、安装配置k8s-node1节点

5、安装k8s-node2节点

6、为所有node节点配置flannel网络

7、配置docker开启加载防火墙规则允许转发数据


一. 环境搭建

1、准备环境 (温馨提示:尽量一次完成集群)

集群很容易断网

1)  计算机说明,建议系统版本7.4或者7.6

主机名IP地址角色硬件

k8s-master

192.168.50.53master+node

Etcd、apiserver、controlor-manager、scheduler、kube-proxy、docker、registry

k8s-node1192.168.50.50node

Kubletel、kube-proxy、docker

k8s-node2192.168.50.51node

Kubletel、kube-proxy、docker

2)  修改主机的计算机名设置host文件

[root@localhost ~]# hostname k8s-master

[root@localhost ~]# bash

[root@k8s-master ~]# vim /etc/hosts

192.168.50.53 k8s-master
192.168.50.50 k8s-node1
192.168.50.51 k8s-node2
~                       

[root@k8s-master ~]# scp /etc/hosts 192.168.50.51:/etc

[root@k8s-master ~]# scp /etc/hosts 192.168.50.50:/etc

2.安装master节点

1)安装etcd配置etcd

[root@k8s-master ~]# yum -y install etcd

[root@k8s-master ~]# cp /etc/etcd/etcd.conf  /etc/etcd/etcd.conf.bak

[root@k8s-master ~]# vim /etc/etcd/etcd.conf

6 ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"

21 ETCD_ADVERTISE_CLIENT_URLS="http://192.168.50.53:2379"

[root@k8s-master ~]# systemctl start etcd

[root@k8s-master ~]# systemctl enable etcd

Created symlink from /etc/systemd/system/multi-user.target.wants/etcd.service to /usr/lib/systemd/system/etcd.service.

2)安装k8s-master节点

[root@k8s-master ~]# yum -y install kubernetes-master.x86_64

3)配置apiserver

[root@k8s-master ~]# vim /etc/kubernetes/apiserver

  1 ###

  2 # kubernetes system config

  3 #

  4 # The following values are used to configure the kube-apiserver

  5 #

  6

  7 # The address on the local server to listen to.

  8 KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"

  9

 10 # The port on the local server to listen on.

 11 KUBE_API_PORT="--port=8080"

 12

 13 # Port minions listen on

 14 KUBELET_PORT="--kubelet-port=10250"

 15

 16 # Comma separated list of nodes in the etcd cluster

 17 KUBE_ETCD_SERVERS="--etcd-servers=http://192.168.50.53:2379"

 18

 19 # Address range to use for services

 20 KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"

 21

 22 # default admission control policies

23KUBE_ADMISSION_CONTROL="admissioncontrol=NamespaceLifecycle,NamespaceExists,LimitRanger,Security    ContextDeny,ResourceQuota"

 24

 25 # Add your own!

 26 KUBE_API_ARGS=""

4) 配置controller和scheduler

[root@k8s-master ~]# vim /etc/kubernetes/config

 22 KUBE_MASTER="--master=http://192.168.50.53:8080"

启动k8s服务

[root@k8s-master ~]# systemctl start kube-apiserver.service

[root@k8s-master ~]# systemctl start kube-controller-manager.service

[root@k8s-master ~]# systemctl start kube-scheduler.service

[root@k8s-master ~]# systemctl enable kube-apiserver.service

Created symlink from /etc/systemd/system/multi-user.target.wants/kube-apiserver.service to /usr/lib/systemd/system/kube-apiserver.service.

[root@k8s-master ~]# systemctl enable kube-controller-manager.service

Created symlink from /etc/systemd/system/multi-user.target.wants/kube-controller-manager.service to /usr/lib/systemd/system/kube-controller-manager.service.

[root@k8s-master ~]# systemctl enable kube-scheduler.server

Failed to execute operation: No such file or directory

[root@k8s-master ~]# systemctl enable kube-scheduler.service

Created symlink from /etc/systemd/system/multi-user.target.wants/kube-scheduler.service to /usr/lib/systemd/system/kube-scheduler.service.

检查节点是否监控

[root@k8s-master ~]# kubectl get componentstatus

NAME                 STATUS    MESSAGE             ERROR

etcd-0               Healthy   {"health":"true"}   

controller-manager   Healthy   ok                  

scheduler            Healthy   ok                  

3、安装k8s-master上的node

1)安装node

[root@k8s-master ~]# yum -y install kubernetes node.x86_64

2)配置kubelet

[root@k8s-master ~]# vim /etc/kubernetes/kubelet

5 KUBELET_ADDRESS="--address=192.168.50.53"

 11 KUBELET_HOSTNAME="--hostname-override=k8s-master"

 14 KUBELET_API_SERVER="--api-servers=http://192.168.50.53:8080"

3)启动kubelet启动自动启动docker服务

[root@k8s-master ~]# systemctl start kubelet

[root@k8s-master ~]# systemctl enable kubelet

Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.

4)启动kubelet-proxy

[root@k8s-master ~]# systemctl start kube-proxy

[root@k8s-master ~]# systemctl enable kube-proxy

Created symlink from /etc/systemd/system/multi-user.target.wants/kube-proxy.service to /usr/lib/systemd/system/kube-proxy.service.

5)检查node节点

[root@k8s-master ~]# kubectl get nodes

NAME         STATUS    AGE

k8s-master   Ready     1m

4、安装配置k8s-node1节点

1)安装node

[root@k8s-node1 ~]# yum -y install kubernetes node.x86_64

2)node1连接k8s-master

[root@k8s-node1 ~]# vim /etc/kubernetes/config

 22 KUBE_MASTER="--master=http://192.168.50.53:8080"

3)配置kubelet

[root@k8s-node1 ~]# vim /etc/kubernetes/kubelet

 5 KUBELET_ADDRESS="--address=192.168.50.50"

 11 KUBELET_HOSTNAME="--hostname-override=k8s-node1"

 14 KUBELET_API_SERVER="--api-servers=http://192.168.50.53:8080"

4)启动服务

[root@k8s-node1 ~]# systemctl start kubelet

[root@k8s-node1 ~]# systemctl start kube-proxy

[root@k8s-node1 ~]# systemctl enable kubelet

Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.

[root@k8s-node1 ~]# systemctl enable kube-proxy

Created symlink from /etc/systemd/system/multi-user.target.wants/kube-proxy.service to /usr/lib/systemd/system/kube-proxy.service.

5)在master节点检测node节点状态

[root@k8s-master ~]# kubectl get nodes

NAME         STATUS    AGE

k8s-master   Ready     13m

k8s-node1    Ready     1m

5、安装k8s-node2节点

1)安装node

[root@k8s-node2 ~]# yum -y install kubernetes node.x86_64

2)node1连接k8s-master

[root@k8s-node2 ~]# vim /etc/kubernetes/config

22 KUBE_MASTER="--master=http://192.168.50.53:8080"

3)配置kubelet

[root@k8s-node2 ~]# vim /etc/kubernetes/kubelet

  5 KUBELET_ADDRESS="--address=192.168.50.51"

 11 KUBELET_HOSTNAME="--hostname-override=k8s-node2"

 14 KUBELET_API_SERVER="--api-servers=http://192.168.50.53:8080"

4)启动服务

[root@k8s-node2 ~]# systemctl start kubelet

[root@k8s-node2 ~]# systemctl start kube-proxy

[root@k8s-node2 ~]# systemctl enable kubelet

Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.

[root@k8s-node2 ~]# systemctl enable kube-proxy

Created symlink from /etc/systemd/system/multi-user.target.wants/kube-proxy.service to /usr/lib/systemd/system/kube-proxy.service.

5)在master节点检测node节点状态

[root@k8s-master ~]# kubectl get nodes

NAME         STATUS    AGE

k8s-master   Ready     19m

k8s-node1    Ready     7m

k8s-node2    Ready     1m

6、为所有node节点配置flannel网络

1)在k8s-master节点安装flannel

[root@k8s-master ~]# yum -y install flannel -y

[root@k8s-master ~]# vim /etc/sysconfig/flanneld

 4 FLANNEL_ETCD_ENDPOINTS="http://192.168.50.53:2379"

[root@k8s-master ~]# etcdctl set /atomic.io/network/config '{"Network":"172.16.0.0/16"}'

{"Network":"172.16.0.0/16"}             //查看多一个网络

[root@k8s-master ~]# systemctl start flanneld    //重新启动docker服务和flannel网络一至

[root@k8s-master ~]# systemctl enable flanneld

Created symlink from /etc/systemd/system/multi-user.target.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service.

Created symlink from /etc/systemd/system/docker.service.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service.

[root@k8s-master ~]# ifconfig         //查看多一个网络

flannel0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1472

        inet 172.16.48.0  netmask 255.255.0.0  destination 172.16.48.0

        inet6 fe80::4fff:f857:41f4:3894  prefixlen 64  scopeid 0x20<link>

        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 500  (UNSPEC)

        RX packets 0  bytes 0 (0.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 3  bytes 144 (144.0 B)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@k8s-master ~]# systemctl restart docker

sys[root@k8s-master ~]# systemctl enable docker

Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

[root@k8s-master ~]# ifconfig

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500

        inet 172.16.48.1  netmask 255.255.255.0  broadcast 0.0.0.0

        ether 02:42:87:58:2f:59  txqueuelen 0  (Ethernet)

        RX packets 0  bytes 0 (0.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 0  bytes 0 (0.0 B)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2)配置node1节点flannel网络

[root@k8s-node1 ~]# yum -y install flannel -y

[root@k8s-node1 ~]# vim /etc/sysconfig/flanneld

 4 FLANNEL_ETCD_ENDPOINTS="http://192.168.50.53:2379"

[root@k8s-node1 ~]# systemctl start flanneld

[root@k8s-node1 ~]# systemctl enable flanneld

Created symlink from /etc/systemd/system/multi-user.target.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service.

Created symlink from /etc/systemd/system/docker.service.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service.

[root@k8s-node1 ~]# systemctl restart docker

[root@k8s-node1 ~]# systemctl enable docker

Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

3)安装node2节点flannel网络

[root@k8s-node2 ~]# yum -y install flannel -y

[root@k8s-node2 ~]# vim /etc/sysconfig/flanneld

 4 FLANNEL_ETCD_ENDPOINTS="http://192.168.50.53:2379"

[root@k8s-node2 ~]# systemctl start flanneld

[root@k8s-node2 ~]# systemctl enable flanneld

Created symlink from /etc/systemd/system/multi-user.target.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service.

Created symlink from /etc/systemd/system/docker.service.wants/flanneld.service to /usr/lib/systemd/system/flanneld.service.

[root@k8s-node2 ~]# systemctl restart docker

sy[root@k8s-node2 ~]# systemctl enable docker

Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

master查看

[root@k8s-master ~]#  kubectl get nodes

NAME         STATUS    AGE

k8s-master   Ready     35m

k8s-node1    Ready     23m

k8s-node2    Ready     17m

4)测试docker容器跨宿主机通信

[root@k8s-master ~]# iptables -P FORWARD ACCEPT

[root@k8s-master ~]#

[root@k8s-node1 ~]# iptables -P FORWARD ACCEPT

[root@k8s-node1 ~]#

[root@k8s-node2 ~]# iptables -P FORWARD ACCEPT

[root@k8s-node2 ~]#

iptables -P FORWARD ACCEPT: 这个命令将iptables的FORWARD链的默认策略设置为ACCEPT(接受)。iptables是Linux上的防火墙工具,它可以用来设置网络规则和过滤器。

-P FORWARD: 指定要更改的链是FORWARD链,这个链控制通过Linux主机的转发流量

ACCEPT: 设置为接受(允许)转发流量,默认情况下,FORWARD链的默认策略是DROP(拒绝)。

#: 这是Linux命令行中用于表示注释的符号。在这个上下文中,#后面的内容被视为注释,不会被执行。

这意味着iptables的FORWARD链的默认策略已被成功更改为接受(ACCEPT),允许通过Linux主机的转发流量。

7、配置docker开启加载防火墙规则允许转发数据

1)配置k8s-master节点

[root@k8s-master ~]# vim /usr/lib/systemd/system/docker.service

 1 [Unit]

  2 Description=Docker Application Container Engine

  3 Documentation=http://docs.docker.com

  4 After=network.target

  5 Wants=docker-storage-setup.service

  6 Requires=docker-cleanup.timer

  7

  8 [Service]

  9 Type=notify

 10 NotifyAccess=main

 11 EnvironmentFile=-/run/containers/registries.conf

 12 EnvironmentFile=-/etc/sysconfig/docker

 13 EnvironmentFile=-/etc/sysconfig/docker-storage

 14 EnvironmentFile=-/etc/sysconfig/docker-network

 15 Environment=GOTRACEBACK=crash

 16 Environment=DOCKER_HTTP_HOST_COMPAT=1

 17 Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin

 18 ExecStartPort=/usr/sbin/iptables -P FORWARD ACCEPT       添加这一行

 19 ExecStart=/usr/bin/dockerd-current \

[root@k8s-master ~]# systemctl daemon-reload

[root@k8s-master ~]# systemctl restart docker

2)配置k8s-node1节点

[root@k8s-node1 ~]#  vim /usr/lib/systemd/system/docker.service

 18 ExecStartPort=/usr/sbin/iptables -P FORWARD ACCEPT

[root@k8s-node1 ~]# systemctl daemon-reload

[root@k8s-node1 ~]# systemctl restart docker

3)配置k8s-node2节点

[root@k8s-node2 ~]# vim /usr/lib/systemd/system/docker.service

 18 ExecStartPort=/usr/sbin/iptables -P FORWARD ACCEPT

[root@k8s-node2 ~]# systemctl daemon-reload

[root@k8s-node2 ~]# systemctl restart docker


http://www.ppmy.cn/news/1031491.html

相关文章

metaRTC7 demo mac/ios编译指南

概要 metaRTC7.0开始全面支持mac/ios操作系统&#xff0c;新版本7.0.023 mac os demo 包含有srs/zlm的推拉流演示。发布版自带了x64版第三方类库&#xff0c;arm版第三方类库还需开发者自己编译。 源码下载 下载文件metartc7.023.7z https://github.com/metartc/metaRTC/re…

行业Demo分享|轻松掌握交通脉络,「智慧城市交通建设」全景呈现

智慧城市交通建设可视化是指将先进的信息技术应用于城市交通领域&#xff0c;通过可视化技术的手段来实现交通建设的智能化和可持续化发展。随着城市化的快速发展和人口的不断增加&#xff0c;城市交通问题一直是人们关注的焦点。传统的城市交通建设方式已经无法满足现代社会对…

2023.08.13 学习周报

文章目录 摘要文献阅读1.题目2.要点3.问题4.解决方案5.本文贡献6.方法6.1 特征选择6.2 时间序列平稳性检测与数据分解6.3 基于GRU神经网络的PM2.5浓度预测 7.实验7.1 网络参数7.2 实验结果7.3 对比实验 8.讨论9.结论10.展望 PINNS模型1.自动微分2.全连接神经网络3.PINNs模型的P…

ECE585 Tomasulo算法:C++ Tomasulo算法模拟器

ECE585 Tomasulo算法&#xff1a;C Tomasulo算法模拟器 在计算机科学中&#xff0c;Tomasulo算法是一种动态调度和动态执行的方法&#xff0c;它可以有效地处理计算机指令的依赖性。这种算法由IBM的Robert Tomasulo发明&#xff0c;最初用于IBM 360/91的浮点单元。在这篇文章中…

HBuilderX

HX 简介下载安装 简介 HBuilderX 是一款由 DCloud 开发的集成开发环境 (IDE)&#xff0c;主要用于前端开发和移动应用开发。它基于 Visual Studio Code 平台&#xff0c;针对 Web 开发、小程序开发、移动端开发等提供了丰富的功能和插件。 DCloud官网: https://www.dcloud.io …

Python脚本之连接MySQL【四】

本文为博主原创&#xff0c;未经授权&#xff0c;严禁转载及使用。 本文链接&#xff1a;https://blog.csdn.net/zyooooxie/article/details/124640412 之前写了篇 Python脚本之连接MySQL【三】&#xff0c;日常使用过程中&#xff0c;代码实际有很多改动&#xff0c;特此更新…

Java数组,简简单单信手沾来~

——数组&#xff0c;一组相同数据类型的数据 一.一维数组 1.数组的基本概念 1&#xff09;数组用于存储多个同一数据类型的数据 2&#xff09;数组是数据类型【引用类型】 3&#xff09;数组的形式&#xff1a;数据类型 [] 4&#xff09;数组的下标从0开始 5&#xff09;数…

考研408 | 【计算机网络】 网络层

导图 网络层&#xff1a; 路由器功能&#xff1a;转发&路由选择 数据平面 数据平面执行的主要功能是根据转发表进行转发&#xff0c;这是路由器的本地动作。 控制平面 1.传统方法/每路由器法&#xff1a; 2.SDN方法&#xff08;Software-Defined Networking) 控制平面中的…