K8S学习笔记-------1.安装部署K8S集群环境

1.修改为root权限

#sudo su   

2.修改主机名

#hostnamectl set-hostname k8s-master01 

3.查看网络地址

sudo nano /etc/netplan/01-netcfg.yaml

在这里插入图片描述

4.使网络配置修改生效

sudo netplan apply

5.修改UUID(某些虚拟机系统,需要设置才能生成UUID)#

  • 查看UUID:dmidecode -s system-uuid

在这里插入图片描述

  • 查看UUID:ls -l /sys/class/dmi/id/product_uuid

在这里插入图片描述

6.修改machine-id

root@k8s-master01:/home/zgq# hostnamectl status
 Static hostname: k8s-master01
       Icon name: computer-vm
         Chassis: vm 🖴
      Machine ID: 6e06b8a62f094742915c390eab08c802
         Boot ID: 2f2ee93655c148ab8d5a231444047515
  Virtualization: kvm
Operating System: Ubuntu 24.04.1 LTS              
          Kernel: Linux 6.8.0-51-generic
    Architecture: x86-64
 Hardware Vendor: sangfor
  Hardware Model: _acloud_
Firmware Version: rel-1.7.5.1-20190822_073655
   Firmware Date: Tue 2014-04-01
    Firmware Age: 10y 8month 3w 2d                
root@k8s-master01:/home/zgq# ls -l /etc/machine-id
-r--r--r-- 1 root root 33 Dec  4 13:42 /etc/machine-id
root@k8s-master01:/home/zgq# cat  /etc/machine-id
6e06b8a62f094742915c390eab08c802
root@k8s-master01:/home/zgq# rm -f   /etc/machine-id
root@k8s-master01:/home/zgq# systemd-machine-id-setup
Initializing machine ID from VM UUID.
root@k8s-master01:/home/zgq# cat  /etc/machine-id
bad4f9616ef844369a8b351e8752d5c6

在这里插入图片描述

7.关闭SWAP分区

kubelet 的默认行为是在节点上检测到交换内存时无法启动。 这意味着要么禁用交换(swap)功能,要么让 kubelet 容忍交换。

  • 若需允许交换分区(swap),请在 kubelet 配置文件中添加 failSwapOn: falsels -,或通过命令行参数指定。 注意:即使设置了 failSwapOn: false,工作负载默认情况下仍无法访问交换空间。 可以通过在 kubelet 配置文件中设置 swapBehavior 来修改此设置。若要使用交换空间, 请设置 swapBehavior 的值,这个值不能是默认的 NoSwap。 更多细节参阅交换内存管理。
  • 要禁用交换分区(swap),可以使用命令 sudo swapoff -a 暂时关闭交换分区功能。 要使此更改在重启后仍然生效,请确保在系统的配置文件(如 /etc/fstab 或 systemd.swap)中禁用交换功能, 具体取决于你的系统配置方式。
    swapoff -a && sysctl -w vm.swappiness=0 # 临时关闭
    sed -ri ‘/[#]*swap/s@^@#@’ /etc/fstab # 基于配置文件关闭
    在这里插入图片描述

8.时区和时间同步配置

  • 设置东8区
root@k8s-master01:/home/zgq# timedatectl set-timezone Asia/Shanghai

在这里插入图片描述

  • 同步阿里云
root@k8s-master01:/home/zgq# ntpdate ntp.aliyun.com

在这里插入图片描述

  • 自动同步:通过计划任务实现时间同步。
root@k8s-master01:/home/zgq# crontab -e
`0 */1 * * * ntpdate time1.aliyun.com
root@k8s-master01:/home/zgq# crontab -l
# m h  dom mon dow   command
0 0 * * * ntpdate ntp.aliyun.com

在这里插入图片描述

9.配置内核转发及网桥过滤

|||所有主机均需要操作

  1. 配置containerd需要的模块,本次执行,手动加载此模块
modprobe -- overlay
modprobe -- br_netfilter

2.开机自动加载所需的内核模块

root@k8s-master01:/home/zgq# cat << EOF | tee /etc/modules-load.d/k8s.conf 
overlay
br_netfilter
EOF
```ap

3.查看已加载的模块
```bash
root@k8s-node2:/home/zgq# lsmod | grep "overlay"
root@k8s-node2:/home/zgq# lsmod | grep "br_netfilter"

在这里插入图片描述

4.添加网桥过滤及内核转发配置文件
# 以下3个参数是containerd所依赖的内核参数

root@k8s-master01:/home/zgq# cat << EOF | tee /etc/sysctl.d/k8s.conf  
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值