貔貅云原生

貔貅云原生

elastic operator 部署

2024-11-21
elastic operator 部署

Elastic Operator 部署

  1. 需要安装自定义CRD
kubectl create -f https://download.elastic.co/downloads/eck/2.15.0/crds.yaml
  1. 需要安装自定义控制器
kubectl apply -f https://download.elastic.co/downloads/eck/2.15.0/operator.yaml
  1. 此时自定义控制器已经安装完毕,可以查看 log
kubectl -n elastic-system logs -f statefulset.apps/elastic-operator
  1. 开始安装 elasticsearch,并且配置 pvc 持久化
# cat elasticsearch-deploy.yaml

apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: elasticsearch
spec:
  version: 8.16.0
  nodeSets:
  - name: default
    count: 3  #3副本
    volumeClaimTemplates:
    - metadata:
        name: elasticsearch-data
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 10Gi
        storageClassName: sh-storageclass
    config:
      node.store.allow_mmap: false  #禁用 mmap 内存映射文件功能
  1. 如果安装成功,则会如下所示
[root@VM-0-15-opencloudos trace]# kubectl get pod,svc
NAME                                         READY   STATUS    RESTARTS   AGE
pod/elasticsearch-es-default-0                  1/1     Running   0          47h
pod/elasticsearch-es-default-1                  1/1     Running   0          47h
pod/elasticsearch-es-default-2                  1/1     Running   0          47h

NAME                                        TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)       AGE
service/elasticsearch-es-default            ClusterIP      None            <none>        9200/TCP      47h
service/elasticsearch-es-http               ClusterIP      192.168.3.234   <none>        9200/TCP      47h
service/elasticsearch-es-internal-http      ClusterIP      192.168.1.183   <none>        9200/TCP      47h
service/elasticsearch-es-transport          ClusterIP      None            <none>        9300/TCP      47h
  1. 获取用户名密码,发起请求
PASSWORD=$(kubectl get secret elasticsearch-es-elastic-user -o go-template='{{.data.elastic | base64decode}}')
echo $PASSWORD

kubectl run -i -t curl --image=centos --rm
[root@busybox /]# curl -u "elastic:gG45x5lzT2eR8IE44571FltV" -k "https://quickstart-es-http.default.svc:9200"
{
  "name" : "elasticsearch-es-default-1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "5hHGTeeATnCdugAeK467xw",
  "version" : {
    "number" : "8.16.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "12ff76a92922609df4aba61a368e7adf65589749",
    "build_date" : "2024-11-08T10:05:56.292914697Z",
    "build_snapshot" : false,
    "lucene_version" : "9.12.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}