青雲KubeSphere 容器平臺部署教程
阿新 • • 發佈:2020-12-04
1.安裝環境
作業系統版本:
#cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
核心版本:
#uname -a
Linux master01 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
機器配置: 8CPU 16G記憶體 100G磁碟 主機名 IP 地址 192.168.26.1 #叢集VIP 192.168.26.2 lb1 192.168.26.3 lb2 192.168.26.4 master01 192.168.26.5 master02 192.168.26.6 master03
2.修改master和node的hosts檔案
# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.26.1 #叢集VIP 192.168.26.2 lb1 192.168.26.3 lb2 192.168.26.4 master01 192.168.26.5 master02 192.168.26.6 master03
3.安裝chrony實現所有伺服器間的時間同步
# yum install chrony -y # systemctl start chronyd # sed -i -e '/^server/s/^/#/' -e '1a server ntp.aliyun.com iburst' /etc/chrony.conf # systemctl restart chronyd # timedatectl set-timezone Asia/Shanghai # timedatectl Local time: Fri 2020-11-27 16:06:42 CST Universal time: Fri 2020-11-27 08:06:42 UTC RTC time: Fri 2020-11-27 08:06:42 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: n/a
4.關閉所有節點的防火牆和selinux
# systemctl stop firewalld && systemctl disable firewalld
# sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
# 主要檢視SELINUX=disabled,如果SELINUX=eabled 需要修改為disabled
# setenforce 0
# getenforce
# 關掉swap
# swapoff -a
# 要永久禁掉swap分割槽,開啟如下檔案註釋掉swap那一行
# vi /etc/fstab
5.配置系統核心引數和調優
配置sysctl核心引數
$ cat > /etc/sysctl.conf <<EOF
vm.max_map_count=262144
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
生效檔案
$ sysctl -p
修改Linux 資源配置檔案,調高ulimit最大開啟數和systemctl管理的服務檔案最大開啟數
$ echo "* soft nofile 655360" >> /etc/security/limits.conf
$ echo "* hard nofile 655360" >> /etc/security/limits.conf
$ echo "* soft nproc 655360" >> /etc/security/limits.conf
$ echo "* hard nproc 655360" >> /etc/security/limits.conf
$ echo "* soft memlock unlimited" >> /etc/security/limits.conf
$ echo "* hard memlock unlimited" >> /etc/security/limits.conf
$ echo "DefaultLimitNOFILE=1024000" >> /etc/systemd/system.conf
$ echo "DefaultLimitNPROC=1024000" >> /etc/systemd/system.conf
6.叢集節點上安裝docker
# 安裝依賴包
# yum install -y yum-utils device-mapper-persistent-data lvm2
# 新增docker軟體包的yum源
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 關閉測試版本list(只顯示穩定版)
# yum-config-manager --enable docker-ce-edge
# yum-config-manager --enable docker-ce-test
# 更新yum包索引
# yum makecache fast
# 安裝docker
# 直接安裝Docker CE
# yum install docker-ce
# 若需要安裝指定版本的Docker CE
# yum list docker-ce --showduplicates|sort -r #找到需要安裝的
# yum install docker-ce-18.06.0.ce -y
#啟動docker
# systemctl start docker & systemctl enable docker
#配置docker 使用阿里雲加速
#vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://q2hy3fzi.mirror.aliyuncs.com"]
}
#systemctl daemon-reload && systemctl restart docker
7. 配置節點間ssh互信
配置ssh互信,那麼節點之間就能無密訪問,方便日後執行自動化部署
# ssh-keygen # 每臺機器執行這個命令, 一路回車即可
# ssh-copy-id node # 到master上拷貝公鑰到其他節點,這裡需要輸入 yes和密碼
8.先來認識一下青雲的kubesphere
官網地址: https://kubesphere.com.cn/
KubeSphere 是在 Kubernetes 之上構建的面向雲原生應用的 容器混合雲,支援多雲與多叢集管理,提供全棧的 IT 自動化運維的能力,簡化企業的 DevOps 工作流。
KubeSphere 提供了運維友好的嚮導式操作介面,幫助企業快速構建一個強大和功能豐富的容器雲平臺。
KubeSphere 願景是打造一個基於 Kubernetes 的雲原生分散式作業系統,它的架構可以很方便地與雲原生生態進行即插即用(plug-and-play)的整合。
9.配置高可用負載均衡節點(在兩個lb節點執行)
在兩個lb 節點上分別安裝haproxy 和 keepalived
#yum install haproxy -y
#systemctl restart haproxy && systemctl enable haproxy
#修改haproxy 的配置檔案
# cat /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
listen stats
mode http
bind 0.0.0.0:9000
stats enable
stats hide-version
stats uri /
stats realm Haproxy\ Statistics
stats admin if TRUE #啟用管理功能
stats hide-version
stats refresh 30s
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
log global
option httplog
option dontlognull
timeout connect 5000
timeout client 5000
timeout server 5000
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend kube-apiserver
bind *:6443
mode tcp
option tcplog
default_backend kube-apiserver
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend kube-apiserver
mode tcp
option tcplog
balance roundrobin
default-server inter 10s downinter 5s rise 2 fall 2 slowstart 60s maxconn 250 maxqueue 256 weight 100
server kube-apiserver-1 192.168.26.4:6443 check
server kube-apiserver-2 192.168.26.5:6443 check
server kube-apiserver-3 192.168.26.6:6443 check
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
frontend ingress-http
bind *:80
default_backend ingress-http
mode tcp
option tcplog
backend ingress-http
balance source
mode tcp
server master1 192.168.26.4:30880 check
server master2 192.168.26.5:30880 check
server master3 192.168.26.6:30880 check
#重啟haproxy服務
#yum install keepalived -y
#systemctl restart keepalived && systemctl enable keepalived
修改keepalived 的 配置檔案:
主節點的配置為:
[root@lb1 ~]# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
}
router_id LVS_DEVEL02
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script chk_haproxy {
script "killall -0 haproxy"
interval 2
weight 2
}
vrrp_instance haproxy-vip {
state BACKUP
priority 90
interface eth0
virtual_router_id 60
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
unicast_src_ip 192.168.26.2
unicast_peer {
192.168.26.3
}
virtual_ipaddress {
192.168.26.1/20
}
track_script {
chk_haproxy
}
}
[root@lb1 ~]#
#備節點的配置為:
[root@lb2 ~]# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
}
smtp_connect_timeout 30
router_id LVS_DEVEL01
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script chk_haproxy {
script "killall -0 haproxy"
interval 2
weight 2
}
vrrp_instance haproxy-vip {
state MASTER
priority 100
interface eth0
virtual_router_id 60
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
unicast_src_ip 192.168.26.3
unicast_peer {
192.168.26.2
}
virtual_ipaddress {
#vip
192.168.26.1/20
}
track_script {
chk_haproxy
}
}
[root@lb2 ~]#
#重啟兩個節點的keepalived
#開啟瀏覽器訪問haproxy 的監控資訊
#http://192.168.26.1:9000/ 我的截圖是後截的,預設負載到後端是紅色的。
10.開始部署青雲KubeSphere 容器平臺(在master01 三操作)
從 v3.0.0 開始,KubeSphere 將基於 ansible 的安裝程式更改為使用 Go 語言開發的名為 KubeKey 的新安裝程式。使用 KubeKey,可以輕鬆、高效、靈活地單獨或整體安裝 Kubernetes 和 KubeSphere。
有三種情況可以使用 KubeKey。
1.僅安裝 Kubernetes
2.用一個命令中安裝 Kubernetes 和 KubeSphere
3.首先安裝 Kubernetes,然後使用 ks-installer 在其上部署 KubeSphere
重要提示:Kubekey 將會幫您安裝 Kubernetes,若已有 Kubernetes 叢集請參考 在 Kubernetes 之上安裝 KubeSphere。
優勢
1.基於 Ansible 的安裝程式具有大量軟體依賴性,例如 Python。KubeKey 是使用 Go 語言開發的,可以消除在各種環境中出現的問題,從而提高安裝成功率。
2.KubeKey 使用 Kubeadm 在節點上儘可能多地並行安裝 K8s 叢集,以降低安裝複雜性並提高效率。與較早的安裝程式相比,它將大大節省安裝時間。
3.KubeKey 支援將群集從 all-in-one 擴充套件到多節點群集甚至 HA 叢集。
4.KubeKey 旨在將群集當作一個物件操作,即 CaaO。
支援的環境
Linux 發行版 Ubuntu 16.04, 18.04 Debian Buster, Stretch CentOS/RHEL 7 SUSE Linux Enterprise Server 15
Kubernetes 版本
v1.15: v1.15.12
v1.16: v1.16.13
v1.17: v1.17.9 (預設)
v1.18: v1.18.6
注意: KubeSphere目前暫不支援執行在k8s 1.19.x之上。
最低資源要求(僅對於最小安裝 KubeSphere):
2 核虛擬 CPU 4 GB 記憶體 20 GB 儲存空間
/var/lib/docker 主要用於儲存容器資料,在使用和操作過程中會逐漸增大。對於生產環境,建議 /var/lib/docker 單獨掛盤。
作業系統要求:
1.SSH 可以訪問所有節點。
2.所有節點的時間同步。
3.sudo/curl/openssl 應在所有節點使用。
4.docker 可以自己安裝,也可以通過 KubeKey 安裝。
5.Red Hat 在其 Linux 發行版本中包括了SELinux,建議關閉SELinux或者將SELinux的模式切換為Permissive[寬容]工作模式
7.建議您的作業系統環境足夠乾淨 (不安裝任何其他軟體),否則可能會發生衝突。
8.如果在從 dockerhub.io 下載映象時遇到問題,建議準備一個容器映象倉庫 (加速器)。為 Docker 守護程式配置映象加速。
9.預設情況下,KubeKey 將安裝 OpenEBS 來為開發和測試環境配置 LocalPV,這對新使用者來說非常方便。對於生產,請使用 NFS/Ceph/GlusterFS 或商業化儲存作為持久化儲存,並在所有節點中安裝相關的客戶端 。
10.如果遇到拷貝時報許可權問題Permission denied,建議優先考慮檢視SELinux的原因。
依賴要求:
KubeKey 可以同時安裝 Kubernetes 和 KubeSphere。根據 KubeSphere 所安裝版本的不同,您所需要安裝的依賴可能也不同。請參考以下表格檢視您是否需要提前在節點上安裝有關的依賴。
網路和 DNS 要求:
確保 /etc/resolv.conf 中的 DNS 地址可用。否則,可能會導致群集中出現某些 DNS 問題。
如果您的網路配置使用防火牆或安全組,則必須確保基礎結構元件可以通過特定埠相互通訊。建議您關閉防火牆或遵循連結配置:網路訪問。
獲取安裝程式可執行檔案
# yum install -y git
# git clone https://github.com/kubesphere/kubekey.git
#cd kubekey-1.0.1
#./build.sh -p
注意:
#在構建之前,需要先安裝 Docker。
#如果無法訪問 https://proxy.golang.org/,比如在大陸,請執行 build.sh -p
建立叢集
這裡我們使用高階用法:
#mkdir /root/kubekey-1.0.1/myfolder/
#cd /root/ kubekey-1.0.1
#./output/kk create config --with-kubesphere -f /root/kubekey-1.0.1/myfolder/config.yaml
創建出來的檔案可按照如下的模版修改:
apiVersion: kubekey.kubesphere.io/v1alpha1
kind: Cluster
metadata:
name: kubesphere
spec:
hosts:
- {name: master01, address: 192.168.26.4, internalAddress: 192.168.26.4, user: root, password: hcy3R0vs0rHhibnfgLvr}
- {name: master02, address: 192.168.26.5, internalAddress: 192.168.26.5, user: root, password: hcy3R0vs0rHhibnfgLvr}
- {name: master03, address: 192.168.26.6, internalAddress: 192.168.26.6, user: root, password: hcy3R0vs0rHhibnfgLvr}
roleGroups:
etcd:
- master01
- master02
- master03
master:
- master01
- master02
- master03
worker:
- master01
- master02
- master03
controlPlaneEndpoint:
domain: kubesphere.alauda.cn
address: "192.168.26.1"
port: "6443"
kubernetes:
version: v1.17.9
imageRepo: kubesphere
clusterName: cluster.local
network:
plugin: calico
kubePodsCIDR: 10.233.64.0/18
kubeServiceCIDR: 10.233.0.0/18
registry:
registryMirrors: []
insecureRegistries: []
addons: []
---
apiVersion: installer.kubesphere.io/v1alpha1
kind: ClusterConfiguration
metadata:
name: ks-installer
namespace: kubesphere-system
labels:
version: v3.0.0
spec:
local_registry: ""
persistence:
storageClass: ""
authentication:
jwtSecret: ""
etcd:
monitoring: true
endpointIps: 192.168.26.4,192.168.26.5,192.168.26.6
port: 2379
tlsEnable: true
common:
es:
elasticsearchDataVolumeSize: 20Gi
elasticsearchMasterVolumeSize: 4Gi
elkPrefix: logstash
logMaxAge: 7
mysqlVolumeSize: 20Gi
minioVolumeSize: 20Gi
etcdVolumeSize: 20Gi
openldapVolumeSize: 2Gi
redisVolumSize: 2Gi
console:
enableMultiLogin: false # enable/disable multi login
port: 30880
alerting:
enabled: true
auditing:
enabled: true
devops:
enabled: true
jenkinsMemoryLim: 2Gi
jenkinsMemoryReq: 1500Mi
jenkinsVolumeSize: 8Gi
jenkinsJavaOpts_Xms: 512m
jenkinsJavaOpts_Xmx: 512m
jenkinsJavaOpts_MaxRAM: 2g
events:
enabled: true
ruler:
enabled: true
replicas: 2
logging:
enabled: true
logsidecarReplicas: 2
metrics_server:
enabled: true
monitoring:
prometheusMemoryRequest: 400Mi
prometheusVolumeSize: 20Gi
multicluster:
clusterRole: none # host | member | none
networkpolicy:
enabled: true
notification:
enabled: true
openpitrix:
enabled: true
servicemesh:
enabled: true
#注意: 由於 Kubernetes 暫不支援大寫 NodeName, worker 節點名中包含大寫字母將導致後續安裝過程無法正常結束
#當指定安裝KubeSphere時,要求叢集中有可用的持久化儲存。預設使用localVolume,如果需要使用其他持久化儲存,請參閱 addons 配置。
#使用配置檔案建立叢集。
#./output/kk create cluster -f /root/kubekey-1.0.1/myfolder/config.yaml
#使用如下命令可檢視部署日誌
# kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
#當出現如下的日誌時候就代表已經部署完成了。(儲存圖片中的登入的地址,使用者名稱和密碼,預設為Account: admin Password: P@88w0rd)
11.啟用 kubectl 自動補全
KubeKey 不會啟用 kubectl 自動補全功能。請參閱下面的指南並將其開啟:
先決條件:確保已安裝 bash-autocompletion 並可以正常工作。
# 安裝 bash-completion
yum -y install bash-completion
# 將 completion 指令碼新增到你的 ~/.bashrc 檔案
echo 'source <(kubectl completion bash)' >>~/.bashrc
# 將 completion 指令碼新增到 /etc/bash_completion.d 目錄
kubectl completion bash >/etc/bash_completion.d/kubectl
**12.登入青雲KubeSphere 容器平臺 **
#瀏覽器開啟: http://kubesphere.alauda.cn/ 使用 Account: admin Password: P@88w0rd 進行登入。