Zer0e's Blog

【架构之路12】es-k8s搭建

字数统计: 572阅读时长: 2 min
2024/07/27 Share

前言

遥想一年前,搭建es时还需要先挂载卷然后hung住容器拷贝配置文件,后面是自己做了镜像。

再到后面切换到k8s后,有了configMap搭建稍微简单了一些。

再到现在,由于要使用es做数据分析,决定搭建一个es节点测试使用。

翻看文档发现官方其实针对k8s有ECK来辅助在k8s上搭建es集群。有点类似之前文章提到的tidb operator。

今天来快速搭建一个es和kibana.

正文

准备

分别创建CRDs和RBAC.

1
2
kubectl create -f https://download.elastic.co/downloads/eck/2.13.0/crds.yaml
kubectl apply -f https://download.elastic.co/downloads/eck/2.13.0/operator.yaml
1
2
3
4
5
6
7
8
customresourcedefinition.apiextensions.k8s.io/agents.agent.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/apmservers.apm.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/beats.beat.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/elasticmapsservers.maps.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/elasticsearches.elasticsearch.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/enterprisesearches.enterprisesearch.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/kibanas.kibana.k8s.elastic.co created
customresourcedefinition.apiextensions.k8s.io/logstashes.logstash.k8s.elastic.co created

es搭建

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: es
namespace: elastic-system
spec:
version: 8.14.3
nodeSets:
- name: default
count: 1
config:
node.store.allow_mmap: false
volumeClaimTemplates:
- metadata:
name: elasticsearch-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
storageClassName: csi-rbd-sc

定义也十分简单,之后apply即可。

定义一个service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
kind: Service
apiVersion: v1
metadata:
name: es-http
namespace: elastic-system
spec:
ports:
- name: http
protocol: TCP
port: 9200
targetPort: 9200
selector:
common.k8s.elastic.co/type: elasticsearch
elasticsearch.k8s.elastic.co/cluster-name: es
type: LoadBalancer

获取下账号密码

1
kubectl get secret es-es-elastic-user -n elastic-system -o go-template='{{.data.elastic | base64decode}}'

访问下应该是正常的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"name": "es-es-default-0",
"cluster_name": "es",
"cluster_uuid": "sxMRMy15QACkzxpSPeTlzA",
"version": {
"number": "8.14.3",
"build_flavor": "default",
"build_type": "docker",
"build_hash": "d55f984299e0e88dee72ebd8255f7ff130859ad0",
"build_date": "2024-07-07T22:04:49.882652950Z",
"build_snapshot": false,
"lucene_version": "9.10.0",
"minimum_wire_compatibility_version": "7.17.0",
"minimum_index_compatibility_version": "7.0.0"
},
"tagline": "You Know, for Search"
}

kibana

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
name: kibana
namespace: elastic-system
spec:
version: 8.14.3
count: 1
elasticsearchRef:
name: es
http:
service:
spec:
type: LoadBalancer
ports:
- port: 5601
targetPort: 5601
tls:
selfSignedCertificate:
disabled: true

这个没什么难度,直接就起来了。

总结

使用ECK十分快速的在k8s上启动了一个es集群,如果后续需要扩容的话,直接修改副本的数量即可,十分简单。

原文作者:Zer0e

原文链接:https://re0.top/2024/07/27/devops12/

发表日期:July 27th 2024, 2:30:00 pm

更新日期:July 27th 2024, 2:47:16 pm

版权声明:本文采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可

CATALOG
  1. 1. 前言
  2. 2. 正文
    1. 2.1. 准备
    2. 2.2. es搭建
    3. 2.3. kibana
  3. 3. 总结