在k8s上搭建elasticsearch 服务

Deploy ECK in your Kubernetes cluster

Deploy ECK in your Kubernetes cluster | Elastic Cloud on Kubernetes [2.1] | Elastic

部署 Elastic Stack

部署 Elastic Stack | 凤凰架构

1. 安装ElasticSearch

1.Install custom resource definitions and the operator with its RBAC rules:

kubectl create -f https://download.elastic.co/downloads/eck/1.9.1/crds.yaml
kubectl apply -f https://download.elastic.co/downloads/eck/1.9.1/operator.yaml

2. Monitor the operator logs:

kubectl -n elastic-system logs -f statefulset.apps/elastic-operator

3. 创建eck 集群

cat <<EOF | kubectl apply -f -
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: quickstart
spec:
  version: 7.17.0
  nodeSets:
  - name: default
    count: 1
    config:
      node.store.allow_mmap: false
EOF

kubectl -n es get elasticsearch

kubectl logs -f quickstart-es-default-0

5. 获取es 集群访问权限

PASSWORD=$(kubectl -n es get secret quickstart-es-elastic-user -o go-template='{{.data.elastic | base64decode}}')
echo "$PASSWORD"


# 在k8s集群同命名空间下的pod内
curl -u "elastic:IQ2DEORp61tfd70Goy76710g" -k "https://quickstart-es-http:9200"


2. 安装kibana

cat <<EOF | kubectl apply -f -
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
  name: quickstart
spec:
  version: 7.9.2
  count: 1
  elasticsearchRef:
    name: quickstart
EOF

2. Monitor Kibana health and creation progress.

Similar to Elasticsearch, you can retrieve details about Kibana instances:

kubectl get kibana

3. 配置 ingress 来访问 es 集群

安装 ingress

https://yuque.antfin.com/ke5an3/rgf45y/myuxgq

禁用 TLS

TLS certificates | Elastic Cloud on Kubernetes [master] | Elastic

You can explicitly disable TLS for Kibana, APM Server, Enterprise Search and the HTTP layer of Elasticsearch.

修改 elasticsearch 的yaml 文件,禁用自签名证书

spec:
  http:
    tls:
      selfSignedCertificate:
        disabled: true

es-ingress.yaml 文件

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  generation: 1
  name: es-ingress
  namespace: es
spec:
  ingressClassName: nginx
  rules:
  - host: es.suoyi.com
    http:
      paths:
      - backend:
          service:
            name: quickstart-es-http
            port:
              number: 9200
        path: /
        pathType: Prefix

创建并验证请求

# 创建 ingress 
kubectl -n es apply -f es-ingress.yaml

# 在节点外进行请求
curl -u "elastic:IQ2DEORp61tfd70Goy76710g" -k "http://es.suoyi.com:31201"

ECK会自动创建一个默认用户elastic,密码存储于k8s secret中:

kibana的用户名和密码同es集群:

4. 通过 自定义镜像 安装ik中文分词器

下载 es版本 对应 ik 分词器和拼音 插件

wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.0.0/elasticsearch-analysis-ik-8.0.0.zip
wget https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v8.0.0/elasticsearch-analysis-pinyin-8.0.0.zip

编写Dockerfile

FROM docker.elastic.co/elasticsearch/elasticsearch:8.0.0
COPY ./elasticsearch-analysis-ik-8.0.0.zip /home/
COPY ./elasticsearch-analysis-pinyin-8.0.0.zip /home/
RUN bin/elasticsearch-plugin install --batch file:/home/elasticsearch-analysis-ik-8.0.0.zip
RUN bin/elasticsearch-plugin install --batch file:/home/elasticsearch-analysis-pinyin-8.0.0.zip

构建定制es镜像

docker build --tag elasticsearch-ik:8.0.0 .

在yaml 文件 指定es镜像

apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: quickstart
spec:
  image: elasticsearch-ik:8.0.0
  auth: {}
  http:
    service:
      metadata: {}
      spec: {}
    tls:
      certificate: {}
      selfSignedCertificate:
        disabled: true
  nodeSets:
  - config:
      node.store.allow_mmap: false
    count: 1
    name: default
    podTemplate:
      spec:
        containers: null
  version: 8.0.0

4. ES 集群监控【TODO】

参考文档

教你在Kubernetes中快速部署ES集群 - 知乎

参考资料

Ingress

Ingress | Kubernetes

how to configure ingress to direct traffic to an https backend using https

kubernetes - how to configure ingress to direct traffic to an https backend using https - Stack Overflow

Elastic Cloud Kubernetes(ECK)安装Elasticsearch、Kibana实战教程

Elastic Cloud Kubernetes(ECK)安装Elasticsearch、Kibana实战教程-阿里云开发者社区

elasticsearch create custom images

Create custom images | Elastic Cloud on Kubernetes [2.1] | Elastic

k8s无脑系列(十一) helm安装ElasticSearch到集群并设置中文分词

k8s无脑系列(十一)-安装ElasticSearch到集群并设置中文分词_smokelee的博客-优快云博客

### 如何在 Kubernetes (k8s) 上部署 Elasticsearch 集群 #### 准备工作 为了成功地在 Kubernetes 上部署 Elasticsearch 集群,需准备以下事项: - 已经安装并配置好 Kubernetes 集群。 - 安装 `kubectl` 命令行工具,并确保其已连接到目标 Kubernetes 集群。 #### 创建命名空间 建议创建一个新的命名空间来管理所有的 Elasticsearch 资源。这有助于保持环境整洁有序[^2]。 ```bash kubectl create namespace elasticsearch ``` #### 使用 Helm 或 Operator 方式简化部署过程 虽然可以直接通过 YAML 文件手动定义和应用各种资源对象,但是使用 Helm Chart 或官方提供的 Elastic Cloud on Kubernetes (ECK) Operator 可以大大减少复杂度并提高可靠性[^3]。 对于 ECK 的方式来说,首先需要安装 operator 自身: ```bash helm repo add elastic https://helm.elastic.co helm install elastic-operator elastic/eck-operator --namespace=elasticsearch ``` 等待几分钟让 operator 启动完成之后就可以继续下一步操作了。 #### 编写自定义资源配置文件 无论是采用哪种方法来进行实际的 ES 实例部署,在大多数情况下都需要编写一些定制化的配置文件。这些文件通常会涉及到 Pod、ServiceAccount、RoleBinding 等多个方面的内容。下面给出一个简单的例子展示如何利用 StatefulSet 和 Service 来构建一个多节点组成的集群。 ```yaml apiVersion: apps/v1 kind: StatefulSet metadata: name: es-cluster spec: serviceName: "es-headless" replicas: 3 selector: matchLabels: app: elasticsearch template: metadata: labels: app: elasticsearch spec: containers: - name: elasticsearch image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0 ports: - containerPort: 9200 name: http env: - name: discovery.type value: "single-node" --- apiVersion: v1 kind: Service metadata: name: elasticsearch-service spec: type: ClusterIP selector: app: elasticsearch ports: - port: 9200 targetPort: http ``` 请注意上述示例仅适用于测试目的;生产环境中应当考虑更多因素如安全性设置(开启 X-Pack 认证)、持久卷声明(PVC)等[^1]。 #### 应用配置文件至 K8S 平台 当所有准备工作都完成后,可以通过如下命令提交之前编写的 yaml 文件给 kubernetes 进行解析执行: ```bash kubectl apply -f ./path/to/es-config.yaml -n elasticsearch ``` 如果一切顺利的话,则可以在几秒钟内看到新的 pod 正常启动运行起来。 #### 设置访问控制机制(可选) 考虑到安全性和权限隔离的需求,可能还需要额外配置 RBAC 规则以及 Secret 对象用来保存账户信息以便后续其他组件能够正常调用 API 接口。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值