1. 参考文档
    https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-overview.html
  2. 制作镜像
    编写dockerfile
FROM docker.elastic.co/elasticsearch/elasticsearch:7.16.2
COPY ik /usr/share/elasticsearch/plugins/ik
COPY pinyin /usr/share/elasticsearch/plugins/pinyin

生成新镜像

#imageName为制作后的镜像名称
docker build -t imageName .
  1. k8s自定义资源等
kubectl create -f https://download.elastic.co/downloads/eck/2.0.0/crds.yaml
kubectl apply -f https://download.elastic.co/downloads/eck/2.0.0/operator.yaml
  1. 创建pv
    编写yaml。一个es节点需要一个pv
apiVersion: v1
kind: PersistentVolume
metadata:
  name: elasticsearch-master
  namespace: elastic-system
  labels:
    type: local
spec:
  storageClassName: elasticsearch-master  #pod与pv通过该标签进行绑定
  capacity:
    storage: 30Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/app/elk/data/master"
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: elasticsearch-data
  namespace: elastic-system
  labels:
    type: local
spec:
  storageClassName: elasticsearch-data  #pod与pv通过该标签进行绑定
  capacity:
    storage: 30Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/app/elk/data/data"
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: elasticsearch-client
  namespace: elastic-system
  labels:
    type: local
spec:
  storageClassName: elasticsearch-client  #pod与pv通过该标签进行绑定
  capacity:
    storage: 30Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/app/elk/data/client"
  1. 创建es
    编写yaml
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: elasticsearchex    #集群名称
  namespace: elastic-system
spec:
  version: 7.16.2  #版本号
  image: docker.elastic.co/elasticsearch/elasticsearch:7.16.2  #镜像,可以自定义镜像,可省略使用官网镜像
  http:
    service:
      spec:
        type: NodePort  #网络类型使用nodeport,默认集群ip
    tls:
      selfSignedCertificate:
        disabled: true   #关闭ssl验证
  nodeSets:
  - name: master-nodes    #主节点设置
    count: 1
    config:
      node.master: true
      node.voting_only: false
      node.data: false
      node.ingest: true
      node.ml: false
      node.store.allow_mmap: false
    podTemplate:
      spec:
        containers:
        - name: elasticsearch
          env:
          - name: ES_JAVA_OPTS
            value: -Xms2g -Xmx2g
          resources:
            limits:
              memory: 4Gi
              cpu: 2
    volumeClaimTemplates:
    - metadata:
        name: elasticsearch-data
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
        storageClassName: elasticsearch-master   #绑定相应pv
  - name: data-nodes     #数据节点设置
    count: 1
    config:
      node.master: false
      node.voting_only: false
      node.data: true
      node.ingest: false
      node.ml: false
      node.store.allow_mmap: false
    podTemplate:
      spec:
        containers:
        - name: elasticsearch
          env:
          - name: ES_JAVA_OPTS
            value: -Xms16g -Xmx16g
          resources:
            limits:
              memory: 32Gi
              cpu: 8
    volumeClaimTemplates:
    - metadata:
        name: elasticsearch-data
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 100Gi
        storageClassName: elasticsearch-data  #绑定对应pv
  - name: client-nodes    #协调节点设置
    count: 1
    config:
      node.master: false
      node.voting_only: false
      node.data: false
      node.ingest: false
      node.ml: false
      node.store.allow_mmap: false
    podTemplate:
      spec:
        containers:
        - name: elasticsearch
          env:
          - name: ES_JAVA_OPTS
            value: -Xms8g -Xmx8g
          resources:
            limits:
              memory: 16Gi
              cpu: 2
    volumeClaimTemplates:
    - metadata:
        name: elasticsearch-data
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
        storageClassName: elasticsearch-client  #绑定对应pv
  1. 创建kibana
    编写yaml
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
  name: kibanaex
  namespace: elastic-system
spec:
  version: 7.16.2
  count: 1
  podTemplate:
      spec:
        containers:
        - name: kibana
          resources:
            limits:
              memory: 2Gi
              cpu: 2
  elasticsearchRef:
    name: elasticsearchex  #对应上方es名称
  1. 获取密码
    k8s部署的es会自动生成一个默认账号elastic 及其对应密码,密码获取方式如下:
#其中加粗部份为上方es名称
kubectl get secret **elasticsearchex**-es-elastic-user -o go-template='{{.data.elastic | base64decode}}' -n elastic-system
  1. 访问kibana
    kibana创建好后会自动生成其对应的 service信息,查询service信息,通过集群ip获取service名称即可访问kibana
    在这里插入图片描述
    或者自行创建nodeport访问,yaml如下
apiVersion: v1
kind: Service
metadata:
  name: hotelkibana-nodeport
  namespace: elastic-system
spec:
  externalTrafficPolicy: Cluster
  ports:
  - name: http
    nodePort: 8601
    port: 8601
    protocol: TCP
    targetPort: 5601
  selector:
    common.k8s.elastic.co/type: kibana
    kibana.k8s.elastic.co/name: kibanaex  #上方kibana名称
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐