ElasticSearch 与 Kibana 的 Helm Chart 模板是 ES 官方 Github 获取的,它的 Github 地址为 https://github.com/elastic/helm-charts 可以访问该地址了解更多信息。

这里只介绍下如何使用 Helm 安装 ElasticSearch 与 Kibana 应用。

环境以及版本信息

软件 版本
Kubernetes 1.17.2
Elasticsearch 7.10.1
Kibana 7.10.1

项目部署在Kubernetes中的elastic命名空间下 kubectl create ns elastic

添加Elastic仓库

(1)、添加Elastic仓库

  1. helm repo add elastic https://helm.elastic.co
  2. helm repo update

(2)、将Elastic Chart包下载到本地

  1. helm pull elastic/elasticsearch

配置ES集群证书

(1)、下载镜像

  1. docker pull docker.elastic.co/elasticsearch/elasticsearch:7.10.1

(2)、制作证书

  1. # 运行容器生成证书
  2. $ docker run --name elastic-charts-certs -i -w /app docker.elastic.co/elasticsearch/elasticsearch:7.10.1 /bin/sh -c \
  3. "elasticsearch-certutil ca --out /app/elastic-stack-ca.p12 --pass '' && \
  4. elasticsearch-certutil cert --name security-master --dns \
  5. security-master --ca /app/elastic-stack-ca.p12 --pass '' --ca-pass '' --out /app/elastic-certificates.p12"
  6. # 从容器中将生成的证书拷贝出来
  7. $ docker cp elastic-charts-certs:/app/elastic-certificates.p12 ./
  8. # 删除容器
  9. $ docker rm -f elastic-charts-certs
  10. # 将 pcks12 中的信息分离出来,写入文件
  11. $ openssl pkcs12 -nodes -passin pass:'' -in elastic-certificates.p12 -out elastic-certificate.pem

(3)、添加证书到Kubernetes

  1. $ kubectl create secret -n elastic generic elastic-certificates --from-file=elastic-certificates.p12
  2. $ kubectl create secret -n elastic generic elastic-certificate-pem --from-file=elastic-certificate.pem

(4)、设置集群用户名和密码

  1. $ kubectl create secret -n elastic generic elastic-credentials \
  2. --from-literal=username=elastic --from-literal=password=elastic@123456

部署ES

(1)、创建Elastic master、data、client节点的配置文件
es-master-values.yaml

  1. # ============设置集群名称============
  2. ## 设置集群名称
  3. clusterName: "elasticsearch"
  4. ## 设置节点名称
  5. nodeGroup: "master"
  6. ## 设置角色
  7. roles:
  8. master: "true"
  9. ingest: "false"
  10. data: "false"
  11. # ============镜像配置============
  12. ## 指定镜像与镜像版本
  13. image: "docker.elastic.co/elasticsearch/elasticsearch"
  14. imageTag: "7.10.1"
  15. ## 副本数
  16. replicas: 1
  17. # ============资源配置============
  18. ## JVM 配置参数
  19. esJavaOpts: "-Xmx1g -Xms1g"
  20. ## 部署资源配置(生成环境一定要设置大些)
  21. resources:
  22. requests:
  23. cpu: "1000m"
  24. memory: "1Gi"
  25. limits:
  26. cpu: "1000m"
  27. memory: "1Gi"
  28. ## 数据持久卷配置
  29. persistence:
  30. enabled: true
  31. ## 存储数据大小配置
  32. volumeClaimTemplate:
  33. storageClassName: managed-nfs-storage
  34. accessModes: [ "ReadWriteOnce" ]
  35. resources:
  36. requests:
  37. storage: 5Gi
  38. # ============安全配置============
  39. ## 设置协议,可配置为 http、https
  40. protocol: http
  41. ## 证书挂载配置,这里我们挂入上面创建的证书
  42. secretMounts:
  43. - name: elastic-certificates
  44. secretName: elastic-certificates
  45. path: /usr/share/elasticsearch/config/certs
  46. ## 允许您在/usr/share/elasticsearch/config/中添加任何自定义配置文件,例如 elasticsearch.yml
  47. ## ElasticSearch 7.x 默认安装了 x-pack 插件,部分功能免费,这里我们配置下
  48. ## 下面注掉的部分为配置 https 证书,配置此部分还需要配置 helm 参数 protocol 值改为 https
  49. esConfig:
  50. elasticsearch.yml: |
  51. xpack.security.enabled: true
  52. xpack.security.transport.ssl.enabled: true
  53. xpack.security.transport.ssl.verification_mode: certificate
  54. xpack.security.transport.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
  55. xpack.security.transport.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
  56. # xpack.security.http.ssl.enabled: true
  57. # xpack.security.http.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
  58. # xpack.security.http.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
  59. ## 环境变量配置,这里引入上面设置的用户名、密码 secret 文件
  60. extraEnvs:
  61. - name: ELASTIC_USERNAME
  62. valueFrom:
  63. secretKeyRef:
  64. name: elastic-credentials
  65. key: username
  66. - name: ELASTIC_PASSWORD
  67. valueFrom:
  68. secretKeyRef:
  69. name: elastic-credentials
  70. key: password
  71. # ============调度配置============
  72. ## 设置调度策略
  73. ## - hard:只有当有足够的节点时 Pod 才会被调度,并且它们永远不会出现在同一个节点上
  74. ## - soft:尽最大努力调度
  75. antiAffinity: "hard"
  76. ## 容忍配置(一般 kubernetes master 或其它设置污点的节点,只有指定容忍才能进行调度,如果测试环境只有三个节点,则可以开启在 master 节点安装应用)
  77. #tolerations:
  78. # - operator: "Exists" ##容忍全部污点

es-data-values.yaml

  1. # ============设置集群名称============
  2. ## 设置集群名称
  3. clusterName: "elasticsearch"
  4. ## 设置节点名称
  5. nodeGroup: "data"
  6. ## 设置角色
  7. roles:
  8. master: "false"
  9. ingest: "true"
  10. data: "true"
  11. # ============镜像配置============
  12. ## 指定镜像与镜像版本
  13. image: "docker.elastic.co/elasticsearch/elasticsearch"
  14. imageTag: "7.10.1"
  15. ## 副本数
  16. replicas: 1
  17. # ============资源配置============
  18. ## JVM 配置参数
  19. esJavaOpts: "-Xmx1g -Xms1g"
  20. ## 部署资源配置(生成环境一定要设置大些)
  21. resources:
  22. requests:
  23. cpu: "1000m"
  24. memory: "2Gi"
  25. limits:
  26. cpu: "1000m"
  27. memory: "2Gi"
  28. ## 数据持久卷配置
  29. persistence:
  30. enabled: true
  31. ## 存储数据大小配置
  32. volumeClaimTemplate:
  33. storageClassName: managed-nfs-storage
  34. accessModes: [ "ReadWriteOnce" ]
  35. resources:
  36. requests:
  37. storage: 10Gi
  38. # ============安全配置============
  39. ## 设置协议,可配置为 http、https
  40. protocol: http
  41. ## 证书挂载配置,这里我们挂入上面创建的证书
  42. secretMounts:
  43. - name: elastic-certificates
  44. secretName: elastic-certificates
  45. path: /usr/share/elasticsearch/config/certs
  46. ## 允许您在/usr/share/elasticsearch/config/中添加任何自定义配置文件,例如 elasticsearch.yml
  47. ## ElasticSearch 7.x 默认安装了 x-pack 插件,部分功能免费,这里我们配置下
  48. ## 下面注掉的部分为配置 https 证书,配置此部分还需要配置 helm 参数 protocol 值改为 https
  49. esConfig:
  50. elasticsearch.yml: |
  51. xpack.security.enabled: true
  52. xpack.security.transport.ssl.enabled: true
  53. xpack.security.transport.ssl.verification_mode: certificate
  54. xpack.security.transport.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
  55. xpack.security.transport.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
  56. # xpack.security.http.ssl.enabled: true
  57. # xpack.security.http.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
  58. # xpack.security.http.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
  59. ## 环境变量配置,这里引入上面设置的用户名、密码 secret 文件
  60. extraEnvs:
  61. - name: ELASTIC_USERNAME
  62. valueFrom:
  63. secretKeyRef:
  64. name: elastic-credentials
  65. key: username
  66. - name: ELASTIC_PASSWORD
  67. valueFrom:
  68. secretKeyRef:
  69. name: elastic-credentials
  70. key: password
  71. # ============调度配置============
  72. ## 设置调度策略
  73. ## - hard:只有当有足够的节点时 Pod 才会被调度,并且它们永远不会出现在同一个节点上
  74. ## - soft:尽最大努力调度
  75. antiAffinity: "hard"
  76. ## 容忍配置(一般 kubernetes master 或其它设置污点的节点,只有指定容忍才能进行调度,如果测试环境只有三个节点,则可以开启在 master 节点安装应用)
  77. #tolerations:
  78. # - operator: "Exists" ##容忍全部污点

es-client-values.yaml

  1. # ============设置集群名称============
  2. ## 设置集群名称
  3. clusterName: "elasticsearch"
  4. ## 设置节点名称
  5. nodeGroup: "client"
  6. ## 设置角色
  7. roles:
  8. master: "false"
  9. ingest: "false"
  10. data: "false"
  11. # ============镜像配置============
  12. ## 指定镜像与镜像版本
  13. image: "docker.elastic.co/elasticsearch/elasticsearch"
  14. imageTag: "7.10.1"
  15. ## 副本数
  16. replicas: 1
  17. # ============资源配置============
  18. ## JVM 配置参数
  19. esJavaOpts: "-Xmx1g -Xms1g"
  20. ## 部署资源配置(生成环境一定要设置大些)
  21. resources:
  22. requests:
  23. cpu: "1000m"
  24. memory: "1Gi"
  25. limits:
  26. cpu: "1000m"
  27. memory: "1Gi"
  28. ## 数据持久卷配置
  29. persistence:
  30. enabled: false
  31. # ============安全配置============
  32. ## 设置协议,可配置为 http、https
  33. protocol: http
  34. ## 证书挂载配置,这里我们挂入上面创建的证书
  35. secretMounts:
  36. - name: elastic-certificates
  37. secretName: elastic-certificates
  38. path: /usr/share/elasticsearch/config/certs
  39. ## 允许您在/usr/share/elasticsearch/config/中添加任何自定义配置文件,例如 elasticsearch.yml
  40. ## ElasticSearch 7.x 默认安装了 x-pack 插件,部分功能免费,这里我们配置下
  41. ## 下面注掉的部分为配置 https 证书,配置此部分还需要配置 helm 参数 protocol 值改为 https
  42. esConfig:
  43. elasticsearch.yml: |
  44. xpack.security.enabled: true
  45. xpack.security.transport.ssl.enabled: true
  46. xpack.security.transport.ssl.verification_mode: certificate
  47. xpack.security.transport.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
  48. xpack.security.transport.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
  49. # xpack.security.http.ssl.enabled: true
  50. # xpack.security.http.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
  51. # xpack.security.http.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
  52. ## 环境变量配置,这里引入上面设置的用户名、密码 secret 文件
  53. extraEnvs:
  54. - name: ELASTIC_USERNAME
  55. valueFrom:
  56. secretKeyRef:
  57. name: elastic-credentials
  58. key: username
  59. - name: ELASTIC_PASSWORD
  60. valueFrom:
  61. secretKeyRef:
  62. name: elastic-credentials
  63. key: password

(2)、创建应用

  1. # 创建Master节点
  2. $ helm install elasticsearch-master -f es-master-values.yaml --namespace elastic --version 7.10.1 elasticsearch
  3. # 创建Data节点
  4. $ helm install elasticsearch-data -f es-data-values.yaml --namespace elastic --version 7.10.1 elasticsearch
  5. # 创建Client节点
  6. $ helm install elasticsearch-client -f es-client-values.yaml --namespace elastic --version 7.10.1 elasticsearch

部署kibana

(1)、下载kibana的chart包

  1. $ helm pull elastic/kibana

(2)、添加kibana配置文件
values.yaml

  1. ---
  2. elasticsearchHosts: "http://elasticsearch-client:9200"
  3. replicas: 1
  4. extraEnvs:
  5. - name: 'ELASTICSEARCH_USERNAME'
  6. valueFrom:
  7. secretKeyRef:
  8. name: elastic-credentials
  9. key: username
  10. - name: 'ELASTICSEARCH_PASSWORD'
  11. valueFrom:
  12. secretKeyRef:
  13. name: elastic-credentials
  14. key: password
  15. envFrom: []
  16. secretMounts: []
  17. image: "docker.elastic.co/kibana/kibana"
  18. imageTag: "7.10.1"
  19. imagePullPolicy: "IfNotPresent"
  20. labels: {}
  21. podAnnotations: {}
  22. resources:
  23. requests:
  24. cpu: "1000m"
  25. memory: "2Gi"
  26. limits:
  27. cpu: "1000m"
  28. memory: "2Gi"
  29. protocol: http
  30. serverHost: "0.0.0.0"
  31. healthCheckPath: "/app/kibana"
  32. kibanaConfig:
  33. kibana.yml: |
  34. i18n.locale: "zh-CN"
  35. podSecurityContext:
  36. fsGroup: 1000
  37. securityContext:
  38. capabilities:
  39. drop:
  40. - ALL
  41. runAsNonRoot: true
  42. runAsUser: 1000
  43. serviceAccount: ""
  44. priorityClassName: ""
  45. httpPort: 5601
  46. extraContainers: ""
  47. extraInitContainers: ""
  48. updateStrategy:
  49. type: "Recreate"
  50. service:
  51. type: ClusterIP
  52. loadBalancerIP: ""
  53. port: 5601
  54. nodePort: ""
  55. labels: {}
  56. annotations: {}
  57. loadBalancerSourceRanges: []
  58. httpPortName: http
  59. ingress:
  60. enabled: true
  61. annotations: {}
  62. path: /
  63. hosts:
  64. - kibana-test.xxx.com
  65. tls: []
  66. readinessProbe:
  67. failureThreshold: 3
  68. initialDelaySeconds: 10
  69. periodSeconds: 10
  70. successThreshold: 3
  71. timeoutSeconds: 5
  72. imagePullSecrets: []
  73. nodeSelector: {}
  74. tolerations: []
  75. affinity: {}
  76. nameOverride: ""
  77. fullnameOverride: ""
  78. lifecycle: {}

(3)、部署kibana

  1. $ helm install kibana -n elastic kibana

待所以pod变成running,即可通过kibana进行访问。
image.png