解锁高效部署!快速搭建Kubernetes集群,提升团队生产力!

2023年 7月 19日 12.4k 0

1 MacOS

1.1 下载 docker-desktop

从 docker 下载 docker-desktop (opens new window),并完成安装

1.2 启用 k8s 集群

启动 docker-desktop,打开preference 面板

切换到 Kubernetes 标签页,并勾选启动 Enable Kubernetes,点击 Apply

2 Linux(CentOS7)

kubernetes.io/zh-cn/docs/…

至少两台机器:

  • k8s master
  • k8s slave

设置好两个主机的 hostname 后,设置配置文件:

2.1 服务器配置最低要求

  • 2g内存
  • 2CPU
  • 30g硬盘
  • 内网互通(防火墙务必关闭)

按照上面的要求创建至少2台(一主一从)云服务器。

2.2 Linux配置

① 设置不同的hostname

 hostnamectl set-hostname xxx 

② 设置host与ip绑定

每个节点都要操作

 vim /etc/hosts
 ​
 ## hosts
 172.17.32.8 k8s-master
 172.17.32.13 k8s-node

③ 关闭firewalld服务

systemctl stop firewalldsystemctl disable firewalld

④ 时间同步

若使用的云服务器,则忽略此步。

因为本地机器和云服务器时间可能不一致,所以需要同步时间。

启动chronyd服务

 systemctl start chronyd
 ​
 systemctl enable chronyddate

img

⑤ 关闭 selinux 安全策略

需要重启后生效!

 [root@icv-monitor-platform-dev ~]# sed -i 's/enforcing/disabled/' /etc/selinux/config
 ​
 [root@icv-monitor-platform-dev ~]# vim /etc/selinux/config
 # This file controls the state of SELinux on the system.
 # SELINUX= can take one of these three values:
 #     enforcing - SELinux security policy is enforced.
 #     permissive - SELinux prints warnings instead of enforcing.
 #     disabled - No SELinux policy is loaded.
 SELINUX=disabled
 # SELINUXTYPE= can take one of three two values:
 #     targeted - Targeted processes are protected,
 #     minimum - Modification of targeted policy. Only selected processes are protected. 
 #     mls - Multi Level Security protection.
 SELINUXTYPE=targeted
 ​
 ​
 # 临时关闭
 [root@icv-monitor-platform-dev ~]# setenforce 0

⑥ 关闭 swap 分区

云服务器没有这个概念,可以不设置。

swap分区指虚拟内存分区,作用是物理内存使用完,之后将磁盘空间虚拟成内存来使用,启用swap设备会对系统的性能产生非常负面的影响,因此k8s要求每个节点都要禁用swap设备。

 vi /etc/fstab
 # /etc/fstab
 # Created by anaconda on Thu May 17 07:47:58 2018
 #
 # Accessible filesystems, by reference, are maintained under '/dev/disk'
 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
 #
 UUID=434ab0f6-eed6-49f5-9118-3744d8cbfb7e /                       ext4    defaults        1 1
 ​
 # 如果有,则注释该⾏
 /dev/mapper/centos-swap swap
 ​
 ​
 # 临时关闭
 swapoff -a
 # 重启
 reboot
 ​
 # 检测  若 total 或者 free 正数,说明你没关闭成功
 [root@icv-monitor-platform-dev ~]# free -m
               total        used        free      shared  buff/cache   available
 Mem:          16045        7769         961         927        7315        7014
 Swap:             0           0           0
 [root@icv-monitor-platform-dev ~]# 

⑦ 添加网桥过滤和地址转发功能

转发 IPv4 并让 iptables 看到桥接流量。

 cat > /etc/sysctl.d/kubernetes.conf

相关文章

KubeSphere 部署向量数据库 Milvus 实战指南
探索 Kubernetes 持久化存储之 Longhorn 初窥门径
征服 Docker 镜像访问限制!KubeSphere v3.4.1 成功部署全攻略
那些年在 Terraform 上吃到的糖和踩过的坑
无需 Kubernetes 测试 Kubernetes 网络实现
Kubernetes v1.31 中的移除和主要变更

发布评论