CC00074.CloudKubernetes——|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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yanqi_vip

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值