helm 搭建elasticsearch + kibana
作者:互联网
现在降本增效搞的需要自己搭建ES环境,大环境是真不好。整了一下午搞定了,记录一下。
由于需要对外网提供环境需要设置密码账号,搭建很简单密码整的老麻烦了。
开始前奏操作 生成secret
# 运行容器生成证书 docker run --name elastic-charts-certs -i -w /app elasticsearch:7.7.1 /bin/sh -c \ "elasticsearch-certutil ca --out /app/elastic-stack-ca.p12 --pass '' && \ elasticsearch-certutil cert --name security-master --dns \ security-master --ca /app/elastic-stack-ca.p12 --pass '' --ca-pass '' --out /app/elastic-certificates.p12" # 从容器中将生成的证书拷贝出来 docker cp elastic-charts-certs:/app/elastic-certificates.p12 ./ # 删除容器 docker rm -f elastic-charts-certs # 将 pcks12 中的信息分离出来,写入文件 openssl pkcs12 -nodes -passin pass:'' -in elastic-certificates.p12 -out elastic-certificate.pem 添加证书和密码到集群 # 添加证书 kubectl create secret generic elastic-certificates --from-file=elastic-certificates.p12 kubectl create secret generic elastic-certificate-pem --from-file=elastic-certificate.pem # 设置集群用户名密码,用户名不建议修改 kubectl create secret generic elastic-credentials \ --from-literal=username=elastic --from-literal=password=123456
配置helm的values
1、es-master-values.yaml
clusterName: "elasticsearch" ## 设置节点名称 nodeGroup: "master" ## 设置角色 roles: master: "true" ingest: "false" data: "false" # ============镜像配置============ ## 指定镜像与镜像版本 image: "docker.elastic.co/elasticsearch/elasticsearch" imageTag: "7.7.1" ## 副本数 replicas: 1 # ============资源配置============ ## JVM 配置参数 esJavaOpts: "-Xmx1g -Xms1g" ## 部署资源配置(生成环境一定要设置大些) resources: requests: cpu: "2000m" memory: "2Gi" limits: cpu: "2000m" memory: "2Gi" ## 数据持久卷配置 persistence: enabled: true ## 存储数据大小配置 volumeClaimTemplate: storageClassName: nfs-storage-new accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 5Gi # ============安全配置============ ## 设置协议,可配置为 http、https protocol: http ## 证书挂载配置,这里我们挂入上面创建的证书 secretMounts: - name: elastic-certificates secretName: elastic-certificates path: /usr/share/elasticsearch/config/certs ## 允许您在/usr/share/elasticsearch/config/中添加任何自定义配置文件,例如 elasticsearch.yml ## ElasticSearch 7.x 默认安装了 x-pack 插件,部分功能免费,这里我们配置下 ## 下面注掉的部分为配置 https 证书,配置此部分还需要配置 helm 参数 protocol 值改为 https esConfig: elasticsearch.yml: | xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12 # xpack.security.http.ssl.enabled: true # xpack.security.http.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12 # xpack.security.http.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12 ## 环境变量配置,这里引入上面设置的用户名、密码 secret 文件 extraEnvs: - name: ELASTIC_USERNAME valueFrom: secretKeyRef: name: elastic-credentials key: username - name: ELASTIC_PASSWORD valueFrom: secretKeyRef: name: elastic-credentials key: password # ============调度配置============ ## 设置调度策略 ## - hard:只有当有足够的节点时 Pod 才会被调度,并且它们永远不会出现在同一个节点上 ## - soft:尽最大努力调度 antiAffinity: "hard" ## 容忍配置(一般 kubernetes master 或其它设置污点的节点,只有指定容忍才能进行调度,如果测试环境只有三个节点,则可以开启在 master 节点安装应用) #tolerations: # - operator: "Exists" ##容忍全部污点
2、es-data-values.yaml
# ============设置集群名称============ ## 设置集群名称 clusterName: "elasticsearch" ## 设置节点名称 nodeGroup: "data" ## 设置角色 roles: master: "false" ingest: "true" data: "true" # ============镜像配置============ ## 指定镜像与镜像版本 image: "docker.elastic.co/elasticsearch/elasticsearch" imageTag: "7.7.1" ## 副本数 replicas: 1 # ============资源配置============ ## JVM 配置参数 esJavaOpts: "-Xmx1g -Xms1g" ## 部署资源配置(生成环境一定要设置大些) resources: requests: cpu: "1000m" memory: "2Gi" limits: cpu: "1000m" memory: "2Gi" ## 数据持久卷配置 persistence: enabled: true ## 存储数据大小配置 volumeClaimTemplate: storageClassName: nfs-storage-new accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 50Gi # ============安全配置============ ## 设置协议,可配置为 http、https protocol: http ## 证书挂载配置,这里我们挂入上面创建的证书 secretMounts: - name: elastic-certificates secretName: elastic-certificates path: /usr/share/elasticsearch/config/certs ## 允许您在/usr/share/elasticsearch/config/中添加任何自定义配置文件,例如 elasticsearch.yml ## ElasticSearch 7.x 默认安装了 x-pack 插件,部分功能免费,这里我们配置下 ## 下面注掉的部分为配置 https 证书,配置此部分还需要配置 helm 参数 protocol 值改为 https esConfig: elasticsearch.yml: | xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12 # xpack.security.http.ssl.enabled: true # xpack.security.http.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12 # xpack.security.http.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12 ## 环境变量配置,这里引入上面设置的用户名、密码 secret 文件 extraEnvs: - name: ELASTIC_USERNAME valueFrom: secretKeyRef: name: elastic-credentials key: username - name: ELASTIC_PASSWORD valueFrom: secretKeyRef: name: elastic-credentials key: password # ============调度配置============ ## 设置调度策略 ## - hard:只有当有足够的节点时 Pod 才会被调度,并且它们永远不会出现在同一个节点上 ## - soft:尽最大努力调度 antiAffinity: "hard" ## 容忍配置(一般 kubernetes master 或其它设置污点的节点,只有指定容忍才能进行调度,如果测试环境只有三个节点,则可以开启在 master 节点安装应用) #tolerations: # - operator: "Exists" ##容忍全部污点
3、es-client-values.yaml
# ============设置集群名称============ ## 设置集群名称 clusterName: "elasticsearch" ## 设置节点名称 nodeGroup: "client" ## 设置角色 roles: master: "false" ingest: "false" data: "false" # ============镜像配置============ ## 指定镜像与镜像版本 image: "docker.elastic.co/elasticsearch/elasticsearch" imageTag: "7.7.1" ## 副本数 replicas: 1 # ============资源配置============ ## JVM 配置参数 esJavaOpts: "-Xmx1g -Xms1g" ## 部署资源配置(生成环境一定要设置大些) resources: requests: cpu: "1000m" memory: "2Gi" limits: cpu: "1000m" memory: "2Gi" ## 数据持久卷配置 persistence: enabled: false # ============安全配置============ ## 设置协议,可配置为 http、https protocol: http ## 证书挂载配置,这里我们挂入上面创建的证书 secretMounts: - name: elastic-certificates secretName: elastic-certificates path: /usr/share/elasticsearch/config/certs ## 允许您在/usr/share/elasticsearch/config/中添加任何自定义配置文件,例如 elasticsearch.yml ## ElasticSearch 7.x 默认安装了 x-pack 插件,部分功能免费,这里我们配置下 ## 下面注掉的部分为配置 https 证书,配置此部分还需要配置 helm 参数 protocol 值改为 https esConfig: elasticsearch.yml: | xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12 # xpack.security.http.ssl.enabled: true # xpack.security.http.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12 # xpack.security.http.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12 ## 环境变量配置,这里引入上面设置的用户名、密码 secret 文件 extraEnvs: - name: ELASTIC_USERNAME valueFrom: secretKeyRef: name: elastic-credentials key: username - name: ELASTIC_PASSWORD valueFrom: secretKeyRef: name: elastic-credentials key: password # ============Service 配置============
4、es-kibana.values.yaml
# ============镜像配置============ ## 指定镜像与镜像版本 image: "docker.elastic.co/kibana/kibana" imageTag: "7.7.1" ## 配置 ElasticSearch 地址 elasticsearchHosts: "http://elasticsearch-client:9200" # ============环境变量配置============ ## 环境变量配置,这里引入上面设置的用户名、密码 secret 文件 extraEnvs: - name: 'ELASTICSEARCH_USERNAME' valueFrom: secretKeyRef: name: elastic-credentials key: username - name: 'ELASTICSEARCH_PASSWORD' valueFrom: secretKeyRef: name: elastic-credentials key: password # ============资源配置============ resources: requests: cpu: "1000m" memory: "2Gi" limits: cpu: "1000m" memory: "2Gi" # ============配置 Kibana 参数============ ## kibana 配置中添加语言配置,设置 kibana 为中文 kibanaConfig: kibana.yml: | i18n.locale: "zh-CN" # ============Service 配置============
helm命令部署
# 添加 Chart 仓库 helm repo add elastic https://helm.elastic.co helm repo update # 安装 ElasticSearch Master 节点 helm install elasticsearch-master -f es-master-values.yaml --version 7.7.1 elastic/elasticsearch # 安装 ElasticSearch Data 节点 helm install elasticsearch-data -f es-data-values.yaml --version 7.7.1 elastic/elasticsearch # 安装 ElasticSearch Client 节点 helm install elasticsearch-client -f es-client-values.yaml --version 7.7.1 elastic/elasticsearch
搞定!
大家可以根据需要修改持久化和kibana的访问方式。
标签:xpack,elastic,##,配置,kibana,elasticsearch,helm,security 来源: https://www.cnblogs.com/yelang-001/p/16521649.html