kubernetes1.16版本的时候安装了elastic on kubernetes(ECK)1.0版本。存储用了local disk文档跑了一年多了。elasticsearch对应版本是7.6.2。现在已完成了kubernetes 1.20.5 containerd cilium hubble 环境的搭建(https://blog.csdn.net/saynaihe/article/details/115187298)并且集成了cbs腾讯云块存储(https://blog.csdn.net/saynaihe/article/details/115212770)。eck也更新到了1.5版本(我能说我前天安装的时候还是1.4.0吗…还好我只是简单应用没有太复杂的变化无非版本变了…那就再来一遍吧)
最早部署的kubernetes1.16版本的eck安装方式https://duiniwukenaihe.github.io/2019/10/21/k8s-efk/多年前搭建的eck1.0版本。
elastic cloud on kubernetes是一种operator的安装方式,很大程度上简化了应用的部署。同样的还有promtheus-operator。
可参照https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-deploy-eck.html官方文档的部署方式。
kubectl apply -f https://download.elastic.co/downloads/eck/1.5.0/all-in-one.yaml
2. 监视操作日志:kubectl -n elastic-system logs -f statefulset.apps/elastic-operator
**
-----------------------分隔符-----------------
我是直接把yaml下载到本地了。
###至于all-in-one.yaml.1后面的1可以忽略了哈哈,第二次加载文件加后缀了。kubectl apply -f all-in-one.yamlkubectl -n elastic-system logs -f statefulset.apps/elastic-operator2. 部署elasticsearch集群1. 定制化elasticsearch 镜像
增加s3插件,修改时区东八区,并添加腾讯云cos的秘钥,并重新打包elasticsearch镜像.
1. DockerFile如下FROM docker.elastic.co/elasticsearch/elasticsearch:7.12.0ARG ACCESS_KEY=XXXXXXXXXARG SECRET_KEY=XXXXXXXARG ENDPOINT=cos.ap-shanghai.myqcloud.comARG ES_VERSION=7.12.0ARG PACKAGES="net-tools lsof"ENV allow_insecure_settings 'true'RUN rm -rf /etc/localtime && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtimeRUN echo 'Asia/Shanghai' > /etc/timezoneRUN if {#foreach from=get_websites(0, 16, true) item=quick#} [ -n "${PACKAGES}" ]; then yum install -y $PACKAGES && yum clean all && rm -rf /var/cache/yum; fiRUN \ /usr/share/elasticsearch/bin/elasticsearch-plugin install --batch repository-s3 && \ /usr/share/elasticsearch/bin/elasticsearch-keystore create && \echo "XXXXXX" | /usr/share/elasticsearch/bin/elasticsearch-keystore add --stdin s3.client.default.access_key && \echo "XXXXXX" | /usr/share/elasticsearch/bin/elasticsearch-keystore add --stdin s3.client.default.secret_key2. 打包镜像并上传到腾讯云镜像仓库,也可以是其他私有仓库
docker build -t ccr.ccs.tencentyun.com/xxxx/elasticsearch:7.12.0 . docker push ccr.ccs.tencentyun.com/xxxx/elasticsearch:7.12.02. 创建elasticsearch部署yaml文件,部署elasticsearch集群
修改了自己打包 image tag ,使用了腾讯云cbs csi块存储。并定义了部署的namespace,创建了namespace logging.
1. 创建部署elasticsearch应用的命名空间kubectl create ns logging
cat <elastic.yamlapiVersion: elasticsearch.k8s.elastic.co/v1kind: Elasticsearchmetadata: name: elastic namespace: loggingspec: version: 7.12.0 image: ccr.ccs.tencentyun.com/XXXX/elasticsearch:7.12.0 http: tls: selfSignedCertificate: disabled: true nodeSets: - name: laya count: 3 podTemplate: spec: containers: - name: elasticsearch env: - name: ES_JAVA_OPTS value: -Xms2g -Xmx2g resources: requests: memory: 4Gi cpu: 0.5 limits: memory: 4Gi cpu: 2 config: node.master: true node.data: true node.ingest: true node.store.allow_mmap: false volumeClaimTemplates: - metadata: name: elasticsearch-data spec: accessModes: - ReadWriteOnce storageClassName: cbs-csi resources: requests: storage: 200GiEOF2. 部署yaml文件并查看应用部署状态
kubectl apply -f elastic.yamlkubectl get elasticsearch -n loggingkubectl get elasticsearch -n loggingkubectl -n logging get pods --selector='elasticsearch.k8s.elastic.co/cluster-name=elastic'3. 获取elasticsearch凭据
kubectl -n logging get secret elastic-es-elastic-user -o=jsonpath='{.data.elastic}' | base64 --decode; echo4. 直接安装kibana了
修改了时区,和elasticsearch镜像一样都修改到了东八区,并将语言设置成了中文,关于selfSignedCertificate原因参照https://www.elastic.co/guide/en/cloud-on-k8s/1.4/k8s-kibana-http-configuration.html。
cat <kibana.yamlapiVersion: kibana.k8s.elastic.co/v1kind: Kibanametadata: name: elastic namespace: loggingspec: version: 7.12.0 image: docker.elastic.co/kibana/kibana:7.12.0 count: 1 elasticsearchRef: name: elastic http: tls: selfSignedCertificate: disabled: true podTemplate: spec: containers: - name: kibana env: - name: I18N_LOCALE value: zh-CN resources: requests: memory: 1Gi limits: memory: 2Gi volumeMounts: - name: timezone-volume mountPath: /etc/localtime readOnly: true volumes: - name: timezone-volume hostPath: path: /usr/share/zoneinfo/Asia/ShanghaiEOF
kubectl apply kibana.yaml5. 对外映射kibana 服务
对外暴露都是用traefik https 代理,命名空间添加tls secret。绑定内部kibana service.然后外部slb udp代理443端口。但是现在腾讯云slb可以挂载多个证书了,就把这层剥离了,直接http方式到80端口 。然后https 证书 都在slb负载均衡代理了。这样省心了证书的管理,还有一点是可以在slb层直接收集接入层日志到cos。并可使用腾讯云自有的日志服务。
cat <ingress.yamlapiVersion: traefik.containo.us/v1alpha1kind: Ingre***outemetadata: name: kibana-kb-http namespace: loggingspec: entryPoints: - web routes: - match: Host(`kibana.XXXXX.com`) kind: Rule services: - name: elastic-kb-http port: 5601EOF kubectl apply -f ingress.yaml
输入 用户名elastic 密码为上面获取的elasticsearch的凭据,进入管理页面。新界面很是酷炫
创建快照仓库跟S3方式是一样的,具体的可以参考https://blog.csdn.net/ypc123ypc/article/details/87860583这篇博文
PUT _snapshot/esbackup{ "type": "s3", "settings": { "endpoint":"cos.ap-shanghai.myqcloud.com", "region": "ap-shanghai", "compress" : "true", "bucket": "elastic-XXXXXXX" }}
OK 进行验证快照仓库是否添加成功
还原一个试试?
可还行?等待变绿
基本完成。正常可以使用了。使用过程中还有很多注意的。关键还是集群的设计规划。数据的预估增长还有报警。下次有时间列一下Elastalert在kubernetes中的部署应用。