Kubesphere之ks-installer介绍
Kubesphere提供兩個(gè)部署工具,KubeKey和ks-installer。其中,ks-installer部署Kubesphere,KubeKey安裝Kubernetes和ks-installer。
代碼框架
controller:shell-operator的兩個(gè)腳本
deploy:部署ks-installer的yaml文件
docs:文檔
env:變量
playbooks:各個(gè)playbook
- alerting.yaml:部署報(bào)警模塊
- auditing:部署審計(jì)模塊
- common:部署通用模塊,包括es、fluent-bit、minio、openldap、mysql等等
- devops:部署devops模塊
- events:部署事件模塊
- harbor:部署鏡像倉庫模塊
- ks-config:
- ks-core:部署ks核心組件,包括ks-apiserver、ks-controller-manager、ks-console等
- logging:部署日志模塊
- metrics-server:部署metrics-server
- monitor:部署監(jiān)控模塊
- multicluster:部署多集群模塊
- openpitrix:部署openpitrix
- preinstall:預(yù)安裝,包括檢查k8s版本、storageclass、helm版本轉(zhuǎn)換等
- result-info:統(tǒng)計(jì)部署結(jié)果,顯示welcome信息
- servicemesh:部署微服務(wù)模塊
- telemetry:獲取一些集群信息,如k8s版本、ks版本、machineID等等,再向ClusterConfiguration寫入- - clusterID(當(dāng)前鏡像有問題,生成clusterID失敗,因?yàn)闆]有uuidgen命令)
roles:各個(gè)role目錄
scripts:ks-installer相關(guān)腳本
shell-operator
ks-installer本質(zhì)是一個(gè)shell-operator,監(jiān)控著ClusterConfiguration資源,當(dāng)ClusterConfiguration資源變化時(shí),則會(huì)觸發(fā)ks-installer的部署流程。
不像fluentbit-operator這些,shell-operator并不是一種具體的operator實(shí)現(xiàn),而是提供了一種框架。按照這種框架,可以編寫出具體的operator。
shell-operator 與其他 Kubernetes 工作負(fù)載類似,部署在 Pod中。在 Pod 中有一個(gè)/hooks 的一個(gè)子目錄,其中存儲(chǔ)了可執(zhí)行文件,它們可以用 Bash、Python、Ruby等編寫的,我們稱這些可執(zhí)行文件為hooks。在這些可執(zhí)行文件中,聲明感興趣的Kubernetes事件,訂閱這些事件,并執(zhí)行這些鉤子。
shell-operator 如何知道何時(shí)執(zhí)行鉤子呢?事實(shí)上每個(gè)鉤子都有兩個(gè)階段。在啟動(dòng)過程中,shell-operator 使用-config參數(shù)運(yùn)行每個(gè)鉤子。一旦配置階段結(jié)束,鉤子將以“正常”方式執(zhí)行:響應(yīng)附加給它們的事件。
shell-operator支持三種鉤子響應(yīng)類型:
1、OnStartup:啟動(dòng)后即運(yùn)行;
2、schedule:crontab格式的定時(shí)任務(wù);
3、kubernetes:監(jiān)控Kubernetes資源,根據(jù)定義的事件類型來響應(yīng);
shell-operator也提供了prometheus metrics,支持自定義指標(biāo),默認(rèn)端口是9115。
bash-5.1$ pwd /hooks/kubesphere bash-5.1$ ls installRunner.py schedule.shks-installer的pod中,/hooks/kubesphere中包含兩個(gè)文件。installRunner.py用于部署ks-installer,schedule.sh定期執(zhí)行telemetry的playbook,檢查狀態(tài)、注冊(cè)clusterid等。
installRunner.py:
schedule.sh:
if [[ $1 == "--config" ]] ; thencat <<EOF {"configVersion":"v1","schedule": [{"allowFailure": true,"name": "every month","crontab": "0 0 1 * *"}] } EOF elseansible-playbook /kubesphere/playbooks/telemetry.yaml -e @/kubesphere/config/ks-config.jsonif [[ $? -eq 0 ]]; then#statementsstr="successsful!"echo -e "$str"elseexitfi fi這兩個(gè)腳本的入口處,都是通過-config參數(shù),配置要監(jiān)控的事件,另外一個(gè)分支,就是鉤子需要處理的動(dòng)作。
schedule.sh是一個(gè)定時(shí)執(zhí)行的任務(wù),每個(gè)月執(zhí)行telemetry.yaml。
installRunner.py就是主要的部署腳本。
installRunner.py
def main():if not os.path.exists(privateDataDir):os.makedirs(privateDataDir)if len(sys.argv) > 1 and sys.argv[1] == "--config":print(ks_hook)else:# 加載k8s配置config.load_incluster_config()# k8s客戶端api = client.CustomObjectsApi()# 生成新的ClusterConfiguration配置generate_new_cluster_configuration(api)# 持久化文件/kubesphere/config/ks-config.json和/kubesphere/config/ks-status.json# /kubesphere/config/ks-config.json即ClusterConfiguration的配置部分(json化)# /kubesphere/config/ks-status.json即CLusterConfiguration的狀態(tài)部分generateConfig(api)# execute preInstall tasks# 執(zhí)行preInstall、metrics-server、common、ks-corepreInstallTasks()# 實(shí)際安裝,異步安裝各組件resultState = getResultInfo()resultInfo(resultState, api)部署
ks-installer容器啟動(dòng)(重啟)后,或者感知到ClusterConfiguration變化后,都會(huì)觸發(fā)ks-installer的部署流程。
每次觸發(fā)部署流程,preInstall、metrics-server、common、ks-core等playbook都會(huì)再次執(zhí)行。
而可插拔組件是否會(huì)執(zhí)行部署,取決于ClusterConfiguration中,對(duì)應(yīng)組件的status狀態(tài),當(dāng)該模塊不存在,或者status不為enalbed時(shí),都會(huì)重新觸發(fā)該模塊的再次部署。如果要調(diào)試某個(gè)組件的重新部署,可以在status部分,刪除對(duì)應(yīng)組件的部分。
參考文章:
https://github.com/flant/shell-operator
https://cloud.tencent.com/developer/article/1701733
https://blog.fleeto.us/post/shell-operator/
總結(jié)
以上是生活随笔為你收集整理的Kubesphere之ks-installer介绍的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 成为一家机器学习公司意味着投资基础技术
- 下一篇: 遗传算法和神经网络结合在税收中的运用