欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

KubeSphere接入外部Elasticsearch實戰(zhàn)示例

 更新時間:2022年12月11日 15:22:23   作者:KubeSphere  
這篇文章主要為大家介紹了KubeSphere接入外部Elasticsearch實戰(zhàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

引言

在安裝完成時候可以啟用日志組件,這樣會安裝 ES 組件并可以收集所有部署組件的日志,也可以收集審計日志,然后可以很方便的在 KubeSphere 平臺上進行日志查詢。

但是在實際使用過程中發(fā)現(xiàn)使用 KubeSphere 自身的 ES 會很重,而且官方也建議我們將日志接入到外部的 ES 中減輕 Kubernetes 的壓力。

以下為操作實戰(zhàn)。

前置步驟

ES 集群需支持 http 協(xié)議

1?? 搭建好外部 ES 集群,使用 http 協(xié)議(非本文重點)。

測試環(huán)境 IP: 172.30.10.226,172.30.10.191,172.30.10.184
port: 9200
username: elastic
password: changeme

2?? 對 ES 做負載均衡。

有三種常見的做法:

  • 使用 nginx 做負載均衡;
  • 單協(xié)調節(jié)點;
  • 通過自定義 service 和 endpoints 負載均衡。

本文檔基于第三種負載均衡方案(通過 endpoints 負載)做對接。

備份 ks-installer

管理員賬號登錄 KubeSphere,在平臺管理 - 集群管理 - CRD 中搜索 clusterconfiguration,在自定義資源中,點擊 ks-installer 選擇編輯 YAML ,復制備份。

關閉內(nèi)部 ES 對接外部 ES(如果未開啟日志則省略)

集群開啟了內(nèi)部 Elasticsearch,會存在如下系統(tǒng)組件和日志接收器

1?? 系統(tǒng)組件:

2?? 日志接收器:

容器日志、資源事件、審計日志(不開啟不會有日志接收器)

接收器地址為內(nèi)部 Elasticsearch 地址:elasticsearch-logging-data.kubesphere-logging-system.svc:9200

關閉內(nèi)部 ES 并卸載日志相關可插拔組件

執(zhí)行命令編輯 ks-installer:

$ kubectl edit cc ks-installer -n kubesphere-system

1?? 卸載日志系統(tǒng),將 ks-installer 參數(shù)的 logging.enabled 字段的值從 true 改為 false

2?? 卸載事件日志系統(tǒng),將 ks-installer 參數(shù)的 events.enabled 字段的值從 true 改為 false。

3?? 卸載審計日志系統(tǒng),將 ks-installer 參數(shù)的 auditing.enabled 字段的值從 true 改為 false。

4?? 配置文件的最后,刪除如下內(nèi)容:

 es:  
    enabledTime: 2022-08-16T10:33:18CST  
    status: enabled  
  events:  
    enabledTime: 2022-04-15T16:22:59CST  
    status: enabled  
  fluentbit:  
    enabledTime: 2022-04-15T16:19:46CST  
    status: enabled  
  logging:  
    enabledTime: 2022-04-15T16:22:59CST  
    status: enabled

執(zhí)行命令檢查安裝過程:

$ kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
#日志出現(xiàn)以下內(nèi)容說明重啟成功
Collecting installation results ...
#####################################################
###              Welcome to KubeSphere!           ###
#####################################################
Console: http://172.30.9.xxx:30880
Account: admin
Password: P@88w0rd
NOTES:
  1. After you log into the console, please check the
     monitoring status of service components in
     "Cluster Management". If any service is not
     ready, please wait patiently until all components 
     are up and running.
  2. Please change the default password after login.
#####################################################
https://kubesphere.io             2022-08-04 15:53:14
#####################################################

執(zhí)行命令卸載相關可插拔組件:

###### 卸載 KubeSphere 日志系統(tǒng)
$ kubectl delete inputs.logging.kubesphere.io -n kubesphere-logging-system tail
###### 卸載 KubeSphere 事件系統(tǒng)
$ helm delete ks-events -n kubesphere-logging-system
###### 卸載 KubeSphere 審計
$ helm uninstall kube-auditing -n kubesphere-logging-system
$ kubectl delete crd rules.auditing.kubesphere.io
$ kubectl delete crd webhooks.auditing.kubesphere.io
###### 卸載包括 Elasticsearch 的日志系統(tǒng)
$ kubectl delete crd fluentbitconfigs.logging.kubesphere.io
$ kubectl delete crd fluentbits.logging.kubesphere.io
$ kubectl delete crd inputs.logging.kubesphere.io
$ kubectl delete crd outputs.logging.kubesphere.io
$ kubectl delete crd parsers.logging.kubesphere.io
$ kubectl delete deployments.apps -n kubesphere-logging-system fluentbit-operator
$ helm uninstall elasticsearch-logging --namespace kubesphere-logging-system
$ kubectl delete deployment logsidecar-injector-deploy -n kubesphere-logging-system
$ kubectl delete ns kubesphere-logging-system

卸載過程中可能出現(xiàn)如下異常:

crd 資源刪除時出現(xiàn)問題,嘗試使用如下命令

$ kubectl patch crd/crd名稱 -p '{"metadata":{"finalizers":[]}}' --type=merge

創(chuàng)建 namespace

$ kubectl create ns kubesphere-logging-system

自定義 service 負載均衡 ES 節(jié)點

es-service.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: es-service
  name: es-service
  namespace: kubesphere-logging-system
spec:
  ports:
  - port: 9200
    name: es
    protocol: TCP
    targetPort: 9200

es-endpoints.yaml

ip 地址修改為真實要對接的 ES 集群節(jié)點的 IP 地址。

apiVersion: v1
kind: Endpoints
metadata:
  labels:
    app: es-service
  name: es-service
  namespace: kubesphere-logging-system
subsets:
- addresses:
  - ip: 172.30.10.***
  - ip: 172.30.10.***
  - ip: 172.30.10.***
  ports:
  - port: 9200
    name: es
    protocol: TCP

執(zhí)行命令創(chuàng)建自定義 SVC:

$ kubectl apply -f es-service.yaml -n kubesphere-logging-system
$ kubectl apply -f es-endpoints.yaml -n kubesphere-logging-system
#查看svc
$ kubectl get svc -n kubesphere-logging-system 
NAME                              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
es-service                        ClusterIP   109.233.8.178    <none>        9200/TCP   10d
#查看endpoints
$ kubectl get ep -n kubesphere-logging-system 
NAME        ENDPOINTS      AGE           es-service                        172.30.10.***:9200,172.30.10.***:9200,172.30.10.***:9200       10d

“平臺管理-集群管理-應用負載-服務”搜索 es-service。

es-service 服務地址:es-service.kubesphere-logging-system.svc。

開啟日志并對接外部 ES

在平臺管理 - 集群管理 - CRD 中搜索 clusterconfiguration,在自定義資源中,點擊 ks-installer,修改配置:

開啟容器日志、審計日志分別修改

logging.enabled: true

auditing.enabled: true

修改外部 ES 配置

es.basicAuth.enabled: true

es.basicAuth.password

es.basicAuth.username

es.externalElasticsearchUrl

es.externalElasticsearchPort

修改日志保存日期(默認 7 天)

logMaxAge

修改日志索引前綴(默認 logstash)

elkPrefix(開發(fā):dev,測試:sit,生產(chǎn):prod)

apiVersion: installer.kubesphere.io/v1alpha1
kind: ClusterConfiguration
metadata:
  labels:
    version: v3.2.1
  name: ks-installer
  namespace: kubesphere-system
spec:
  alerting:
    enabled: false
  auditing:
    enabled: true            # false改為true
  ...
    es:
      basicAuth:
        enabled: true          # false改為true
        password: '****'       # 密碼
        username: '****'       # 用戶名
      data:
        volumeSize: 20Gi
      elkPrefix: sit           #開發(fā):dev 測試:sit 生產(chǎn):prod
      externalElasticsearchPort: '9200' # 端口
      externalElasticsearchUrl: es-service.kubesphere-logging-system.svc # 修改es-service
      logMaxAge: 7             #默認7天即可          
      master:
        volumeSize: 4Gi
    ...

執(zhí)行命令檢查安裝過程

$ kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
#日志出現(xiàn)以下內(nèi)容說明重啟成功
Collecting installation results ...
#####################################################
###              Welcome to KubeSphere!           ###
#####################################################
Console: http://172.30.9.xxx:30880
Account: admin
Password: P@88w0rd
NOTES:
  1. After you log into the console, please check the
     monitoring status of service components in
     "Cluster Management". If any service is not
     ready, please wait patiently until all components 
     are up and running.
  2. Please change the default password after login.
#####################################################
https://kubesphere.io             2022-08-04 15:53:14
#####################################################

執(zhí)行命令,查看對應的 ConfigMap 配置:

$ kubectl get configmap kubesphere-config -n kubesphere-system -o yaml  
#重點如下,看es的配置是否已經(jīng)生效,host是否為自定義SVC,以及用戶名密碼索引是否正確
    logging:
      host: http://es-service.kubesphere-logging-system.svc:9200
      basicAuth: True
      username: "****"  #此處為你填寫的正確用戶名
      password: "****"  #此處為你填寫的正確密碼
      indexPrefix: ks-sit-log  #不同環(huán)境對應dev\sit\prod
    auditing:
      enable: true
      webhookURL: https://kube-auditing-webhook-svc.kubesphere-logging-system.svc:6443/audit/webhook/event
      host: http://es-service.kubesphere-logging-system.svc:9200
      basicAuth: True
      username: "****"  #此處為你填寫的正確用戶名
      password: "****"  #此處為你填寫的正確密碼
      indexPrefix: ks-sit-auditing #不同環(huán)境對應dev\sit\prod

執(zhí)行命令編輯對應 output(如果已自動修改則不需要手動修改):

  • 修改 host
  • 修改索引 (開發(fā)、測試、生產(chǎn)前綴分別對應 ks-dev-、ks-sit-、ks-prod-)
#修改es的output
$ kubectl edit output es -n kubesphere-logging-system
#修改host 和 logstashPrefix
# host: es-service.kubesphere-logging-system.svc
# logstashPrefix: ks-對應環(huán)境-log
#如下:
spec:
  es:
    generateID: true
    host: es-service.kubesphere-logging-system.svc  # host地址
    httpPassword:
      valueFrom:
        secretKeyRef:
          key: password
          name: elasticsearch-credentials
    httpUser:
      valueFrom:
        secretKeyRef:
          key: username
          name: elasticsearch-credentials
    logstashFormat: true
    logstashPrefix: ks-sit-log  # 修改此處為對應環(huán)境的日志索引
    port: 9200
    timeKey: '@timestamp'
  matchRegex: '(?:kube|service)\.(.*)'
#修改es-auditing的output
$ kubectl edit output es-auditing -n kubesphere-logging-system
#修改host 和 logstashPrefix
# host: es-service.kubesphere-logging-system.svc
# logstashPrefix: ks-對應環(huán)境-auditing
#如下
spec:
  es:
    generateID: true
    host: es-service.kubesphere-logging-system.svc  # host地址
    httpPassword:
      valueFrom:
        secretKeyRef:
          key: password
          name: elasticsearch-credentials
    httpUser:
      valueFrom:
        secretKeyRef:
          key: username
          name: elasticsearch-credentials
    logstashFormat: true
    logstashPrefix: ks-sit-auditing   # 修改此處為對應環(huán)境的日志索引
    port: 9200
  match: kube_auditing

重啟 ks-apiserver

$ kubectl rollout restart deployment ks-apiserver -n kubesphere-system

驗證

$ kubectl get po -n kubesphere-logging-system 
NAME                                                              READY   STATUS      RESTARTS   AGE
elasticsearch-logging-curator-elasticsearch-curator-276864h2xt2   0/1     Error       0          38h
elasticsearch-logging-curator-elasticsearch-curator-276864wc6bs   0/1     Completed   0          38h
elasticsearch-logging-curator-elasticsearch-curator-276879865wl   0/1     Completed   0          14h
elasticsearch-logging-curator-elasticsearch-curator-276879l7xpf   0/1     Error       0          14h
fluent-bit-4vzq5                                                  1/1     Running     0          47h
fluent-bit-6ckvm                                                  1/1     Running     0          25h
fluent-bit-6jt8d                                                  1/1     Running     0          47h
fluent-bit-88crg                                                  1/1     Running     0          47h
fluent-bit-9ps6z                                                  1/1     Running     0          47h
fluent-bit-djhtx                                                  1/1     Running     0          47h
fluent-bit-dmpfv                                                  1/1     Running     0          47h
fluent-bit-dtr7z                                                  1/1     Running     0          47h
fluent-bit-flxbt                                                  1/1     Running     0          47h
fluent-bit-fnxdk                                                  1/1     Running     0          47h
fluent-bit-gqbrl                                                  1/1     Running     0          47h
fluent-bit-kbzsj                                                  1/1     Running     0          47h
fluent-bit-lbnnh                                                  1/1     Running     0          47h
fluent-bit-nq4g8                                                  1/1     Running     0          47h
fluent-bit-q5shz                                                  1/1     Running     0          47h
fluent-bit-qrb7v                                                  1/1     Running     0          47h
fluent-bit-r26fk                                                  1/1     Running     0          47h
fluent-bit-rfrpd                                                  1/1     Running     0          47h
fluent-bit-s8869                                                  1/1     Running     0          47h
fluent-bit-sp5k4                                                  1/1     Running     0          47h
fluent-bit-vjvhl                                                  1/1     Running     0          47h
fluent-bit-xkksv                                                  1/1     Running     0          47h
fluent-bit-xrlz4                                                  1/1     Running     0          47h
fluentbit-operator-745bf5559f-vnz8w                               1/1     Running     0          47h
kube-auditing-operator-84857bf967-ftbjr                           1/1     Running     0          47h
kube-auditing-webhook-deploy-64cfb8c9f8-hf8g8                     1/1     Running     0          47h
kube-auditing-webhook-deploy-64cfb8c9f8-zf4rd                     1/1     Running     0          47h
logsidecar-injector-deploy-5fb6fdc6dd-fj5vm                       2/2     Running     0          47h
logsidecar-injector-deploy-5fb6fdc6dd-qbhdg                       2/2     Running     0          47h

日志接收器:

查詢審計日志:

以上就是KubeSphere接入外部Elasticsearch實戰(zhàn)示例的詳細內(nèi)容,更多關于KubeSphere接入Elasticsearch的資料請關注腳本之家其它相關文章!

相關文章

  • kubernetes數(shù)據(jù)持久化StorageClass動態(tài)供給實現(xiàn)詳解

    kubernetes數(shù)據(jù)持久化StorageClass動態(tài)供給實現(xiàn)詳解

    這篇文章主要為大家介紹了kubernetes數(shù)據(jù)持久化StorageClass動態(tài)供給實現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • CKAD認證中部署k8s并配置Calico插件

    CKAD認證中部署k8s并配置Calico插件

    這篇文章介紹了CKAD認證中部署k8s并配置Calico插件的方法,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-03-03
  • k8s集群部署時etcd容器不停重啟問題以及處理詳解

    k8s集群部署時etcd容器不停重啟問題以及處理詳解

    一次在k8s集群中創(chuàng)建實例發(fā)現(xiàn)etcd集群狀態(tài)出現(xiàn)連接失敗狀況,導致創(chuàng)建實例失敗,下面這篇文章主要給大家介紹了關于k8s集群部署時etcd容器不停重啟問題以及處理的相關資料,需要的朋友可以參考下
    2023-01-01
  • kubectl中get命令及使用示例總結

    kubectl中get命令及使用示例總結

    這篇文章主要為大家介紹了kubectl中get命令及使用示例的總結,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-03-03
  • Kubernetes ApiServer三大server權限與數(shù)據(jù)存儲解析

    Kubernetes ApiServer三大server權限與數(shù)據(jù)存儲解析

    這篇文章主要為大家介紹了Kubernetes ApiServer三大server權限與數(shù)據(jù)存儲解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • K8S集群范圍使用imagePullSecret示例詳解

    K8S集群范圍使用imagePullSecret示例詳解

    在這篇文章中,我將向你展示如何在?Kubernetes?中使用?imagePullSecrets示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • Kubernetes?controller?manager運行機制源碼解析

    Kubernetes?controller?manager運行機制源碼解析

    這篇文章主要為大家介紹了Kubernetes?controller?manager運行機制源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • Kubernetes(K8S)容器集群管理環(huán)境完整部署詳細教程-上篇

    Kubernetes(K8S)容器集群管理環(huán)境完整部署詳細教程-上篇

    本系列文章主要介紹了Kubernetes(K8S)容器集群管理環(huán)境完整部署的詳細教程,分為上中下三篇文章,此為上篇,需要的朋友可以參考下
    2022-01-01
  • Kubernetes(K8S)容器集群管理環(huán)境完整部署詳細教程-下篇

    Kubernetes(K8S)容器集群管理環(huán)境完整部署詳細教程-下篇

    本系列文章主要介紹了Kubernetes(K8S)容器集群管理環(huán)境完整部署的詳細教程,分為上中下三篇文章,此為中篇,主要講解了K8S部署metrics-server插件,K8S部署集群dashboard插件,K8S部署集群coredns插件,K8S部署kube-state-metrics插件,K8S部署harbor私有倉庫
    2022-01-01
  • kubernetes實現(xiàn)分布式限流

    kubernetes實現(xiàn)分布式限流

    這篇文章介紹了kubernetes實現(xiàn)分布式限流的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04

最新評論