快速搭建Kubernetes集群

server/2024/9/24 0:36:01/

快速搭建Kubernetes集群

1 MacOS

1.1 下载

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

1.2 启用 k8s 集群

启动 docker-desktop,打开preference 面板

alt

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

alt

2 Linux(CentOS7)

https://kubernetes.io/zh-cn/docs/setup/production-environment/

至少两台机器:

  • 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 firewalld

systemctl disable firewalld
④ 时间同步

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

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

启动chronyd服务

systemctl start chronyd

systemctl enable chronyddate
alt
⑤ 关闭 selinux 安全策略

需要重启后生效!

$ sed -i 's/enforcing/disabled/' /etc/selinux/config

$ 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
# 临时关闭
$ 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 正数,说明你没关闭成功
$ free -m
              total        used        free      shared  buff/cache   available
Mem:          16045        7769         961         927        7315        7014
Swap:             0           0           0
⑦ 添加网桥过滤和地址转发功能

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

cat > /etc/sysctl.d/kubernetes.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF

# 应⽤ sysctl 参数使其⽣效⽽不重新启动
$ sysctl --system

基础环境(每台云服务器)

  • 安装JDK环境
  • 安装Docker,设置开机自启动

配置cgroup

vim /etc/docker/daemon.json

{
  "registry-mirrors": ["https://4t9ixk24.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}

保证 k8s 和 docker 使用同一个systemd。

重启刷新

[root@javaedge-monitor-platform-dev ~]# systemctl daemon-reload
[root@javaedge-monitor-platform-dev ~]# systemctl restart docker
# 验证cgroupdriver 是否⽣效,看到systemd就表示OK
[root@javaedge-k8s-node-2 ~]# docker info -f {{.CgroupDriver}}
systemd
[root@javaedge-k8s-node-2 ~]
[root@javaedge-k8s-node-1 ~]# docker info | grep -i cgroup
Cgroup Driver: systemd
Cgroup Version: 1
[root@javaedge-k8s-node-1 ~]

以上内容全部配置好以后,重启 。所有节点都要执行以上操作!!!

获取更多干货内容,记得关注我哦。

本文由 mdnice 多平台发布


http://www.ppmy.cn/server/121061.html

相关文章

4.C++中程序中的命名空间

咱们在前面的程序中&#xff0c;提到过使用using namespace std;引入这个命名空间&#xff0c;那么std就是由编程系统提供的标准命名空间&#xff0c;那什么是命名空间呢&#xff1f; 想像一下&#xff0c;比如一个年级的学生&#xff0c;在记录的时候出现了重名的情况&#x…

Elasticsearch:一次生产集群 ES Watcher 失效的深度排查与分析 - 全过程剖析与解决方案

作者&#xff1a;尚雷&#xff0c;TechTalk 技术交流社区创办者 一次生产集群 ES Watcher 失效的深度排查与分析 全过程剖析与解决方案​​ 一、Elasticsearch Watcher 介绍 1.1 Watcher 概念概述 Watcher 是 Elasticsearch 提供的一项监控和告警服务&#xff0c;允许用户定义…

vue node node-sass sass-loader 版本 对应 与 兼容

警告&#xff1a; LibSass 和 Node Sass 已弃用。虽然它们将继续无限期地接收维护版本&#xff0c;但没有计划添加其他功能或与任何新的 CSS 或 Sass 功能兼容。仍在使用它的项目应该转移到 Dart Sass。 sass Sass是一种预处理器脚本语言&#xff0c;可以解释或编译成…

全栈开发(三):springBoot3中使用mybatis-plus

MyBatis-Plus &#x1f680; 为简化开发而生 (baomidou.com) 1.配置pom.xml <dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-spring-boot3-starter</artifactId><version>3.5.7</version></dependency&g…

设计模式 组合模式(Composite Pattern)

组合模式简绍 组合模式&#xff08;Composite Pattern&#xff09;是一种结构型设计模式&#xff0c;它允许你将对象组合成树形结构来表示“部分-整体”的层次结构。组合模式使得客户端可以用一致的方式处理单个对象和组合对象。这样&#xff0c;可以在不知道对象具体类型的条…

在Android中fragment的生命周期

目录 Fragment 生命周期主要包括以下几个阶段&#xff1a; 详细Kotlin代码和中文注释 生命周期解释&#xff1a; 总结&#xff1a; 在Android中&#xff0c;Fragment 的生命周期类似于 Activity&#xff0c;但有其独特之处。以下是 Fragment 生命周期的主要方法&#xff0c…

如何理解MVCC

MVCC是什么&#xff1f; MVCC&#xff0c;是MultiVersion Concurrency Control的缩写&#xff0c;翻译成中文就是多版本并发控制&#xff0c;多个事务同时访问同一数据时&#xff0c;调控每一个事务获取到数据的具体版本。和数据库锁一样&#xff0c;它也是一种并发控制的解决…

蓝桥杯嵌入式的学习总结

一. 前言 嵌入式竞赛实训平台(CT117E-M4) 是北京国信长天科技有限公司设计&#xff0c;生产的一款 “ 蓝桥杯全国软件与信息技术专业人才大赛-嵌入式设计与开发科目 “ 专用竞赛平台&#xff0c;平台以STM32G431RBT6为主控芯片&#xff0c;预留扩展板接口&#xff0c;可为用户提…