本文将会详细介绍,基于Elastic stack技术构建kubernetes平台的可观察性整体解决方案。
为什么要使用可观测性解决方案
可观测性是一种非功能性要求,随着组织采用云技术而变得越来越必要,从而增加了运行时的复杂性。但是,基于日志、指标和跟踪组合的遥测数据可让你了解应用程序、服务和基础架构的执行情况。
可观察性建立在标准监控实践的概念之上。 虽然监控功能会告诉你服务已关闭或处于错误状态,但可观察性功能允许团队通过询问数据问题来主动调试和理解错误,而无需预先定义调查所需的确切数据点。 能够观察你的环境需要深入了解业务的每个堆栈和层,并能够将相关事件和组件关联并拼接在一起。
环境信息
kubernetes:v1.18.8
Elasticsearch: v8.3.3
kibana: v8.3.3
使用8.3.3 版本的原因主要是helm仓库中用该版本打包的,当前官方最新版是8.4
安装步骤
通过helm安装es和kibana,希望了解helm的用途请参考: Helm | Docs
helm repo add bitnami https://charts.bitnami.com/bitnami # 将bitnami helm 仓储添加到本地
helm search repo elastic # 验证一下仓库是否添加成功,检索一下,下图是检索结果
kubectl create namespace xxx-logging-system # 创建用于elastic stack的ns
helm install es bitnami/elasticsearch -n xxx-logging-system
helm install kibana bitnami/kibana -n xxx-logging-system
自定义配置
建议将helm包拉取到本地,便于自定义配置
helm pull bitnami/elasticsearch helm pull bitnami/kibana
helm包的文件结构基本上是固定的,这里不多介绍helm的文件作用,主要查看values.yaml 文件,如下:
以下通过一个例子,说明怎么自定义修改配置。
开启es和kibana安全配置的方式
- 通过 elasticsearch-setup-passwords 初始化系统账号,参考 :elasticsearch-setup-passwords | Elasticsearch Guide [8.4] | Elastic
- es开启安全认证,修改values.yaml 文件,截取部分示例,该版本已经继承了x-pack组件,只需要修改配置就可以了,注释写的非常详实,需要修改的配置的时候先查看注释。
security:
## @param security.enabled Enable X-Pack Security settings
##
enabled: true
## @param security.elasticPassword Password for 'elastic' user
## Ref: https://github.com/bitnami/containers/tree/main/bitnami/elasticsearch#security
##
elasticPassword: "changeme"
## @param security.existingSecret Name of the existing secret containing the Elasticsearch password and
##
existingSecret: ""
## FIPS mode
## @param security.fipsMode Configure elasticsearch with FIPS 140 compliant mode
## Ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/fips-140-compliance.html
##
fipsMode: false
## TLS configuration
##
- 在extraConfig节,开启api auth
注意:默认情况下会生成elasticsearch.yml文件,extraConfig部分的内容会合并到elasticsearch.yml中
#extraConfig: {}
extraConfig:
xpack:
security:
authc:
api_key:
enabled: true
- kibana开启安全认证,注意看注释,kinana使用的是'kibana_system'用户。
security:
auth:
## @param elasticsearch.security.auth.enabled Set to 'true' if Elasticsearch has authentication enabled
##
enabled: true
## @param elasticsearch.security.auth.kibanaPassword Password of the 'kibana_system' user, used to authenticate Kibana connection with Elasticsearch.
##
kibanaPassword: "changeme"
## @param elasticsearch.security.auth.existingSecret Name of the existing secret containing the password for the 'kibana_system' user.
##
existingSecret: ""
## @param elasticsearch.security.auth.createSystemUser If enabled, Kibana will use Elasticsearch API to create the 'kibana_system' user at startup.
##
createSystemUser: false
## @param elasticsearch.security.auth.elasticsearchPasswordSecret Name of the existing secret containing the password for the 'elastic' user.
## Required if createSystemUser=true. The secret must containt the key 'elasticsearch-password'.
##
elasticsearchPasswordSecret: ""
- 通过helm 调整应用配置
helm upgrade es ./elasticsearch -n xxx-logging-system # es为helm创建应用时定义的release name ./elasticsearch 为helm包的根目录路径。
helm upgrade kibana ./kibana -n xxx-logging-system # kibana为helm创建应用时定义的release name ./kibana 为helm包的根目录路径。
- 开启安全后,登录kibana会要求认证