1. 程式人生 > 其它 >|NO.Z.00024|——————————|^^ 部署 ^^|——|KuberNetes&二進位制部署.V02|5臺Server|---------------------------------------|基礎配置|

|NO.Z.00024|——————————|^^ 部署 ^^|——|KuberNetes&二進位制部署.V02|5臺Server|---------------------------------------|基礎配置|



[CloudNative:KuberNetes&二進位制部署.V02]                                                            [Applications.KuberNetes] [|DevOps|k8s|**5節點**|二進位制1.20|安裝說明|基礎環境配置|] [|網路規劃|時間同步|swap關閉|NetworkManager|limit|SSH免密登入|系統升級|]








一、基礎環境配置

### --- 基礎環境配置說明

~~~     主機資訊,伺服器IP地址不能設定成dhcp,要配置成靜態IP。
~~~     VIP(虛擬IP)不要和公司內網IP重複,首先去ping一下,不通才可用。
~~~     VIP需要和主機在同一個區域網內!
~~~     公有云的話,VIP為公有云的負載均衡的IP,
~~~     比如阿里雲的SLB地址,騰訊雲的ELB地址,注意公有云的負載均衡都是內網的負載均衡。
二、網路規劃:
### --- 主機資訊,伺服器IP地址不能設定成dhcp,要配置成靜態IP

[root@k8s-master01 ~]# vim /etc/hosts
centos7.x 10.10.10.11    192,168.1.11     # master01    2C2G 40G
centos7.x 10.10.10.12    192,168.1.12     # master02    2C2G 40G
centos7.x 10.10.10.13    192,168.1.13     # master03    2C2G 40G
centos7.x 10.10.10.20    192.168.1.20     # VIP:虛擬IP不佔用資源 如果不是高可用叢集該IP為Master01的IP
centos7.x 10.10.10.14    192,168.1.14     # node01      2C2G 40G
centos7.x 10.10.10.15    192,168.1.15     # node01      2C2G 40G

~~~     10.96.0.0/12    // k8s Service網段:訪問Pod服務是通過Pod來訪問的,所以service也需要有一個IP地址。
~~~     172.16.0.0/12   // k8s Pod網段:可以理解為容器的IP地址,pod是管理容器的。會有一個IP地址。

~~~     以上三個網段是不可以重複的。
~~~     # VIP(虛擬IP)不要和公司內網IP重複,首先去ping一下,不通才可用。
~~~     # VIP需要和主機在同一個區域網內!公有云的話,VIP為公有云的負載均衡的IP,
~~~     比如阿里雲的SLB地址,騰訊雲的ELB地址,注意公有云的負載均衡都是內網的負載均衡。

~~~     # 官網地址:https://kubernetes.io/:Getting started
~~~     ——>Release  notes and  v1.20 Release Notes
~~~     ——>Server Binarles:kubernetes-server-linux-amd64.tar.gz
~~~     下載地址:也可以在GitHub上下載。
~~~     # 檢視版本之家的變更:Changelog sincev1.19.0:可以檢視版本變更:
~~~     放棄了docker的檢視:Dockershim deprecation20.1.23版本之後放棄這個外掛。
~~~     # 生產環境中,建議使用小版本大於5的kubernetes版本,
~~~     比如1.19.5/2.20.5以後的才可用於生產環境。


一、系統基礎環境配置

### --- 系統核心版本

[root@k8s-master01 ~]#  cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core)

### --- 配置所有節點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
### --- CentOS 7安裝yum源且安裝必備工具

~~~     # 下載centos.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   4083      0 --:--:-- --:--:-- --:--:--  4082

~~~     # 安裝必備工具

[root@k8s-master01 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
~~~     # 安裝docker的yum源

[root@k8s-master01 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
~~~     # 更改為阿里雲的yum源地址
[root@k8s-master01 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
 
~~~     # 安裝必備工具
[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 wget jq psmisc vim net-tools yum-utils device-mapper-persistent-data lvm2 git -y

### --- 所有節點關閉firewalld 、dnsmasq、selinux(CentOS7需要關閉NetworkManager,CentOS8不需要)

~~~     # 永久關閉firewalld
[root@k8s-master01 ~]# systemctl disable --now firewalld 
 
~~~     # 永久關閉dnsmasq 
[root@k8s-master01 ~]# systemctl disable --now dnsmasq

~~~     # 永久關閉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.
~~~     # 臨時關閉selinux 
[root@k8s-master01 ~]# setenforce 0
setenforce: SELinux is disabled
 
~~~     # 永久關閉selinux
[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
### --- 所有節點關閉swap分割槽,fstab註釋swap

~~~     # 臨時關閉swap分割槽
[root@k8s-master01 ~]# swapoff -a && sysctl -w vm.swappiness=0
vm.swappiness = 0
~~~     # 將swap分割槽的關閉引數寫入配置檔案
[root@k8s-master01 ~]# sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab

二、基礎環境配置:時間同步

### --- 所有節點同步時間:安裝ntpdate

~~~     # 安裝ntpdate的yum源地址
[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

### --- 時間同步

~~~     # 同步時間
[root@k8s-master01 ~]# ntpdate time2.aliyun.com
 9 Apr 15:22:05 ntpdate[10480]: adjust time server 203.107.6.88 offset -0.277817 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 

四、kubernetes基礎配置:k8s-master01免密登入

### --- k8s-master01免密登入說明

~~~     Master01節點免金鑰登入其他節點,安裝過程中生成配置檔案和證書均在Master01上操作,
~~~     叢集管理也在Master01上操作,
~~~     阿里雲或者AWS上需要單獨一臺kubectl伺服器。
### --- k8s-master01金鑰配置如下:

~~~     # k8s-master01上配置生成祕鑰
[root@k8s-master01 ~]# ssh-keygen -t rsa
 
~~~     # k8s-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 w








===============================END===============================


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



來自為知筆記(Wiz)