|NO.Z.00074|——————————|^^ 部署 ^^|——|KuberNetes&kubeadm.V03|5台Server|——|基础配置|
一、kubernetes.kubeadm基础环境配置
### --- 基础环境配置——所有节点
~~~ 查看系统内核版本
[root@k8s-master01 ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
### --- 所有节点配置hosts;修改/etc/hosts配置文件如下
~~~ 配置部署节点hosts配置文件
[root@k8s-master01 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.11 k8s-master01
192.168.1.12 k8s-master02
192.168.1.13 k8s-master03
192.168.1.20 k8s-master-lb # 如果不是高可用集群,该IP为Master01的IP
192.168.1.14 k8s-node01
192.168.1.15 k8s-node02
二、配置repo源——所有节点
### --- 配置centos7.yum源地址
~~~ # 配置centos7.aliyun.repo源
[root@k8s-master01 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2523 100 2523 0 0 3306 0 --:--:-- --:--:-- --:--:-- 3311
~~~ # 更改centos.aliyun.repo源地址为阿里云repo源连接
[root@k8s-master01 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
### --- 配置docker-ce.repo源
~~~ 安装docker.repo源
[root@k8s-master01 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
### --- 配置kubernetes.io.repo源
~~~ 安装kubernetes.repo源
[root@k8s-master01 ~]# cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
### --- 安装基础软件包
~~~ # kubeadm环境必备工具安装
[root@k8s-master01 ~]# yum install wget jq psmisc vim net-tools telnet yum-utils device-mapper-persistent-data lvm2 git -y
~~~ # 安装必备工具
[root@k8s-master01 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
三、禁用系统组件——所有节点
### --- 禁用防火墙
~~~ 将firewalld设置为开机自关闭状态
[root@k8s-master01 ~]# systemctl disable --now firewalld
### --- 禁用selinux
~~~ 将selinux设置为开机自关闭状态
[root@k8s-master01 ~]# setenforce 0
[root@k8s-master01 ~]#sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux
[root@k8s-master01 ~]#sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
### --- 禁用dnsmasq
~~~ 将dnsmasq设置为开机自关闭状态
[root@k8s-master01 ~]# systemctl disable --now dnsmasq
### --- 禁用NetworkManager
~~~ 将NetworkManager设置为开机自关闭状态
[root@k8s-master01 ~]# systemctl disable --now NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
### --- 禁用swap分区
~~~ # 临时关闭swap
[root@k8s-master01 ~]# swapoff -a && sysctl -w vm.swappiness=0
vm.swappiness = 0
~~~ # 彻底关闭:写入配置文件
[root@k8s-master01 ~]# sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab
四、配置时间同步服务——所有节点
### --- 配置wlnmp.repo源
[root@k8s-master01 ~]# rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
Retrieving http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:wlnmp-release-centos-2-1 ################################# [100%]
### --- 安装ntpdate服务
[root@k8s-master01 ~]# yum install ntpdate -y
### --- 设置上海时区软链接
[root@k8s-master01 ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@k8s-master01 ~]# echo 'Asia/Shanghai' >/etc/timezone
### --- 同步aliyun时间
[root@k8s-master01 ~]# ntpdate time2.aliyun.com
10 Jul 16:26:24 ntpdate[10442]: adjust time server 203.107.6.88 offset 0.069374 sec
### --- 设置开机自动同步时间
~~~ 设置开机自动同步:同步时间加入到crontab
[root@k8s-master01 ~]# crontab -e
*/5 * * * * /usr/sbin/ntpdate time2.aliyun.com
五、配置limit——所有节点
### --- 临时生效:limit配置
[root@k8s-master01 ~]# ulimit -SHn 65535
### --- 永久生效:limit配置:写入配置文件
[root@k8s-master01 ~]# vim /etc/security/limits.conf
# 末尾添加如下内容
* soft nofile 655360
* hard nofile 131072
* soft nproc 655350
* hard nproc 655350
* soft memlock unlimited
* hard memlock unlimited
六、配置k8s-master免密登录——k8s-master01节点
### --- ssh秘钥证书概述
~~~ Master01节点免密钥登录其他节点,
~~~ 安装过程中生成配置文件和证书均在Master01上操作,集群管理也在Master01上操作,
~~~ 阿里云或者AWS上需要单独一台kubectl服务器。
### --- 配置ssh-keygen并配置同步其它节点
~~~ # k8s-master01配置主机公钥及私钥
[root@k8s-master01 ~]# ssh-keygen -t rsa
~~~ # 将master01公钥发送到其它节点
[root@k8s-master01 ~]# for i in k8s-master01 k8s-master02 k8s-master03 k8s-node01 k8s-node02;do ssh-copy-id -i .ssh/id_rsa.pub $i;done
七、系统升级并重启——所有节点
### --- 系统升级并重启——所有节点
~~~ 所有节点升级系统并重启,此处升级没有升级内核,下节会单独升级内核:
~~~ 注:CentOS7需要升级,CentOS8可以按需升级系统
[root@k8s-master01 ~]# yum update -y --exclude=kernel* && reboot
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)