微服架構(gòu)基礎(chǔ)設(shè)施環(huán)境平臺(tái)搭建 -(四)在Kubernetes集群基礎(chǔ)上搭建Kubesphere平臺(tái)
通過采用微服相關(guān)架構(gòu)構(gòu)建一套以Kubernetes+Docker為自動(dòng)化運(yùn)維基礎(chǔ)平臺(tái),以微服務(wù)為服務(wù)中心,在此基礎(chǔ)之上構(gòu)建業(yè)務(wù)中臺(tái),并通過Jekins自動(dòng)構(gòu)建、編譯、測(cè)試、發(fā)布的自動(dòng)部署,形成一套完整的自動(dòng)化運(yùn)維、發(fā)布的快速DevOps平臺(tái)。
本文是基于Kubernets集群基礎(chǔ)上來部署Kubesphere的,搭建Kubernetes集群參見【微服架構(gòu)基礎(chǔ)設(shè)施環(huán)境平臺(tái)搭建 -(三)Docker+Kubernetes集群搭建】
Kubesphere詳情參見【官方網(wǎng)站】
詳情參照Kubesphere官方文檔【在 Kubernetes 上最小化安裝 KubeSphere】
微服架構(gòu)基礎(chǔ)設(shè)施環(huán)境平臺(tái)搭建 系列文章
微服架構(gòu)基礎(chǔ)設(shè)施環(huán)境平臺(tái)搭建 -(一)基礎(chǔ)環(huán)境準(zhǔn)備
微服架構(gòu)基礎(chǔ)設(shè)施環(huán)境平臺(tái)搭建 -(二)Docker私有倉(cāng)庫(kù)Harbor服務(wù)搭建
微服架構(gòu)基礎(chǔ)設(shè)施環(huán)境平臺(tái)搭建 -(三)Docker+Kubernetes集群搭建
微服架構(gòu)基礎(chǔ)設(shè)施環(huán)境平臺(tái)搭建 -(四)在Kubernetes集群基礎(chǔ)上搭建Kubesphere平臺(tái)
微服架構(gòu)基礎(chǔ)設(shè)施環(huán)境平臺(tái)搭建 -(五)Docker常用命令
一、微服架構(gòu)采用的技術(shù)架構(gòu)
序號(hào) | 技術(shù)框架 | 說明 |
---|---|---|
1 | Kubernetes | |
2 | Kubesphere | Kubernetes編排器,管理平臺(tái),類似的平臺(tái)還有Rancher |
3 | Docker | |
4 | Harbor | Docker私有倉(cāng)庫(kù) |
5 | GitLab | 源碼庫(kù) |
6 | Jekins | 自動(dòng)編譯、測(cè)試、發(fā)布平臺(tái) |
7 | Spring Cloud Alibaba | Spring Cloud Alibaba微服體系架構(gòu) |
8 | Nacos | Api網(wǎng)關(guān)、服務(wù)注冊(cè)發(fā)現(xiàn)配置管理中心 |
9 | Sentinel | 限流溶斷安全中心 |
10 | Seata | 分布式事務(wù)管理框架 |
11 | Redis | 分布式緩存服務(wù) |
12 | ElasticSearch/Solr | 數(shù)據(jù)檢索服務(wù) |
13 | Mysql | 結(jié)構(gòu)化數(shù)據(jù)存儲(chǔ) |
14 | Grafana | 監(jiān)控平臺(tái) |
15 | Nginx | 服務(wù)代理、Web服務(wù) |
二、微服架構(gòu)基礎(chǔ)設(shè)施平臺(tái)網(wǎng)絡(luò)規(guī)劃
序號(hào) | IP | HostName | 操作系統(tǒng) | K8s角色 | 說明 |
---|---|---|---|---|---|
1 | 192.168.1.141 | ks-m1 | CentOS7_x64 | 控制節(jié)點(diǎn) | Kubernetes Master |
2 | 192.168.1.142 | ks-m2 | CentOS7_x64 | 控制節(jié)點(diǎn) | Kubernetes Master高可用節(jié)點(diǎn),如果不需要高可用,可不部署此服務(wù)器 |
3 | 192.168.1.143 | ks-m3 | CentOS7_x64 | 控制節(jié)點(diǎn) | Kubernetes Master高可用節(jié)點(diǎn),如果不需要高可用,可不部署此服務(wù)器 |
4 | 192.168.1.144 | ks-n1 | CentOS7_x64 | 工作節(jié)點(diǎn) | Kubernetes Worker |
5 | 192.168.1.145 | ks-n2 | CentOS7_x64 | 工作節(jié)點(diǎn) | Kubernetes Worker |
6 | 192.168.2.146 | ks-harbor | CentOS7_x64 | 工作節(jié)點(diǎn) | Harbor服務(wù)+NFS文件服務(wù) |
三、部署架構(gòu)
四、部署NFS提供外部共享存儲(chǔ)
1、在ks-harbor服務(wù)器部署NFS服務(wù)
yum install -y nfs-common nfs-utils
# 分配權(quán)限
mkdir /nfsdata && chmod 666 /nfsdata && chown nfsnobody /nfsdata
# 配置掛載
vim /etc/exports
/nfsdata *(rw,no_root_squash,no_all_squash,sync)
#systemctl start nfs && systemctl enable nfs && systemctl status nfs
#啟動(dòng)
systemctl start rpcbind && systemctl start nfs
# 使配置生效
exportfs -r
#檢查配置是否生效
exportfs
#重載配置文件,不需要重啟服務(wù)
exportfs -arv
2、在ks-n1、ks-n2服務(wù)器部署NFS客戶端
分別在ks-n1、ks-n2執(zhí)行下面的命令
# 安裝nfs
yum install -y nfs-utils
systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-server
#用showmount -e查看遠(yuǎn)程服務(wù)器rpc提供的可掛載的nfs信息
showmount -e 192.168.2.146
#創(chuàng)建掛載點(diǎn)目錄(可自行定義)
mkdir -p /nfsdata
#執(zhí)行掛載命令,完成后測(cè)試文件是否共享
mount -t nfs 192.168.2.146:/nfsdata /nfsdata
#配置客戶端重啟時(shí)自動(dòng)掛載
vim /etc/fstab
新增內(nèi)容
192.168.2.146:/nfsdata /nfsdata nfs defaults 0 0
#查看掛載是否成功
df -h
五、為Kubenetes集群配置NFS存儲(chǔ)
本操作所有命令都在ks-m1服務(wù)器上執(zhí)行
1、新建sc.yaml
mkdir /home/hxyl/sc
cd /home/hxyl/sc
vim sc.yaml
sc.yaml的內(nèi)容
## 創(chuàng)建了一個(gè)存儲(chǔ)類
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: nfs-storage
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: k8s-sigs.io/nfs-subdir-external-provisioner
parameters:
archiveOnDelete: "true" ## 刪除pv的時(shí)候,pv的內(nèi)容是否要備份
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nfs-client-provisioner
labels:
app: nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: nfs-client-provisioner
template:
metadata:
labels:
app: nfs-client-provisioner
spec:
serviceAccountName: nfs-client-provisioner
containers:
- name: nfs-client-provisioner
image: registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/nfs-subdir-external-provisioner:v4.0.2
# resources:
# limits:
# cpu: 10m
# requests:
# cpu: 10m
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: k8s-sigs.io/nfs-subdir-external-provisioner
- name: NFS_SERVER
value: 192.168.2.146 ## 指定自己nfs服務(wù)器地址
- name: NFS_PATH
value: /nfsdata ## nfs服務(wù)器共享的目錄
volumes:
- name: nfs-client-root
nfs:
server: 192.168.2.146
path: /nfsdata
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: nfs-client-provisioner-runner
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "watch", "create", "delete"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: run-nfs-client-provisioner
subjects:
- kind: ServiceAccount
name: nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
roleRef:
kind: ClusterRole
name: nfs-client-provisioner-runner
apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: leader-locking-nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: leader-locking-nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
subjects:
- kind: ServiceAccount
name: nfs-client-provisioner
# replace with namespace where provisioner is deployed
namespace: default
roleRef:
kind: Role
name: leader-locking-nfs-client-provisioner
apiGroup: rbac.authorization.k8s.io
2、執(zhí)行發(fā)布安裝
# 執(zhí)行發(fā)布安裝
kubectl apply -f sc.yaml
# 查看nfs-client-provisioner pod 是否安裝成功
kubectl get pod -A
六、安裝Kubesphere
1、下載并發(fā)布安裝Kubesphere
# 下載核心文件并將其pod發(fā)布到Kubernetes中
kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.3.2/kubesphere-installer.yaml
# 執(zhí)行完此命令后需要通過下面【2、通過日志實(shí)時(shí)顯示安裝進(jìn)度】命令查看安裝進(jìn)度,大概需要幾分鐘的時(shí)間
kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.3.2/cluster-configuration.yaml
2、通過日志實(shí)時(shí)顯示安裝進(jìn)度
#查看安裝進(jìn)度
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f
3、登錄Web控制臺(tái)
說明:
1、訪問3個(gè)Master節(jié)點(diǎn)(ks-m1、ks-m2、ks-m3)任何一個(gè)節(jié)點(diǎn)的30880端口即可。例如:http://192.168.1.141:30880
2、默認(rèn)的用戶名:admin,默認(rèn)的密碼:P@88w0rd
七、體驗(yàn)Kubesphere平臺(tái)
說明:
下面部分截圖中顯示的是3個(gè)節(jié)點(diǎn),原因是開始部署的5臺(tái)虛擬機(jī)由于資源有限,服務(wù)器跑不動(dòng)了,導(dǎo)致集群節(jié)點(diǎn)不可用,后來,將集群節(jié)點(diǎn)由5個(gè)降為3個(gè)節(jié)點(diǎn):
1、Master節(jié)點(diǎn):ks-m1
2、Worker節(jié)點(diǎn):ks-m2、ks-n1
1、登錄
1)、登錄畫面
2)、初次登錄時(shí)修改初始密碼畫面
2、首頁(yè)
1)、登錄成功后首頁(yè)
2)、平臺(tái)管理首頁(yè)
3、集群節(jié)點(diǎn)管理
1)、集群節(jié)點(diǎn)列表管理畫面
2)、集群節(jié)點(diǎn)詳情畫面
4、監(jiān)控告警
八、啟用DevOps插件
1、進(jìn)入集群管理
登錄Web控制臺(tái)后->平臺(tái)管理->集群管理
2、定制資源定義
1)、搜索框內(nèi)輸入【clusterconfiguration】
2)、進(jìn)入ClusterConfiguration詳情畫面后編輯ks-insaller的YAML
3)、將devops下的enabled值改為true
改值改為true后,點(diǎn)擊【確定】后保存并關(guān)閉彈窗口,并在稍后會(huì)提示“更新成功”
4)、查看安裝進(jìn)度
安裝過程會(huì)持續(xù)幾分鐘,執(zhí)行下面命令可以查看實(shí)時(shí)安裝日志
# 在ks-m1上執(zhí)行
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f
九、在Kubesphere上部署一個(gè)Harbor上的鏡像服務(wù)
1、創(chuàng)建企業(yè)空間
2、創(chuàng)建項(xiàng)目
3、創(chuàng)建訪問Harbor的令牌
項(xiàng)目詳情->配置->保密字典
4、創(chuàng)建服務(wù)
項(xiàng)目詳情->應(yīng)用負(fù)載->服務(wù)
說明
1、無(wú)狀態(tài)服務(wù):無(wú)數(shù)據(jù)數(shù)據(jù)持久化的服務(wù)
2、有狀態(tài)服務(wù):數(shù)據(jù)需要持久化的服務(wù)
由于我們是要?jiǎng)?chuàng)建mysql服務(wù),所以選有狀態(tài)
配置完成后點(diǎn)擊【對(duì)鉤】
文章來源:http://www.zghlxwxcb.cn/news/detail-443351.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-443351.html
到了這里,關(guān)于微服架構(gòu)基礎(chǔ)設(shè)施環(huán)境平臺(tái)搭建 -(四)在Kubernetes集群基礎(chǔ)上搭建Kubesphere平臺(tái)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!