谷粒商城-部署-94-K8S 部署 Elasticsearch&Kibana

一、创建ES配置文件

file

file

二、创建存储卷PVC

file

三、创建有状态服务

容器镜像选择:elasticsearch:7.4.2
设置环境变量:
file

挂载存储:
file

然后点击下一步,创建服务成功。
file

查看创建的yaml配置文件:

kind: Pod
apiVersion: v1
metadata:
  name: elasticsearch-oezrwd-0
  generateName: elasticsearch-oezrwd-
  namespace: gulimall
  labels:
    app: elasticsearch
    controller-revision-hash: elasticsearch-oezrwd-7c95c6c5b8
    statefulset.kubernetes.io/pod-name: elasticsearch-oezrwd-0
  annotations:
    kubesphere.io/containerSecrets: ''
    logging.kubesphere.io/logsidecar-config: '{}'
spec:
  volumes:
    - name: volume-dvj8t4
      persistentVolumeClaim:
        claimName: elasticsearch-pvc
    - name: default-token-jcbp7
      secret:
        secretName: default-token-jcbp7
        defaultMode: 420
  containers:
    - name: container-v8we58
      image: 'elasticsearch:7.4.2'
      ports:
        - name: tcp-9200
          containerPort: 9200
          protocol: TCP
        - name: tcp-9300
          containerPort: 9300
          protocol: TCP
      env:
        - name: ES_JAVA_OPTS
          valueFrom:
            configMapKeyRef:
              name: elastic-search-conf
              key: ES_JAVA_OPTS
        - name: discovery.type
          valueFrom:
            configMapKeyRef:
              name: elastic-search-conf
              key: discovery.type
        - name: http.host
          valueFrom:
            configMapKeyRef:
              name: elastic-search-conf
              key: http.host
      resources:
        limits:
          cpu: 1200m
          memory: 1650Mi
        requests:
          cpu: 10m
          memory: 10Mi
      volumeMounts:
        - name: volume-dvj8t4
          mountPath: /usr/share/elasticsearch/data
        - name: default-token-jcbp7
          readOnly: true
          mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      imagePullPolicy: IfNotPresent
  restartPolicy: Always
  terminationGracePeriodSeconds: 30
  dnsPolicy: ClusterFirst
  serviceAccountName: default
  serviceAccount: default
  nodeName: master
  securityContext: {}
  hostname: elasticsearch-oezrwd-0
  subdomain: elasticsearch
  affinity: {}
  schedulerName: default-scheduler
  tolerations:
    - key: node.kubernetes.io/not-ready
      operator: Exists
      effect: NoExecute
      tolerationSeconds: 300
    - key: node.kubernetes.io/unreachable
      operator: Exists
      effect: NoExecute
      tolerationSeconds: 300
  priority: 0
  enableServiceLinks: true

四、测试ES

然后在其他容器中,通过提供的域名:elasticsearch.gulimall,测试是否能够访问ES服务:

# curl http://elasticsearch.gulimall:9200
{
  "name" : "elasticsearch-oezrwd-0",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "dA3CwdCpRQCNyldGP1XdOw",
  "version" : {
    "number" : "7.4.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "2f90bbf7b93631e52bafb59b3b049cb44ec25e96",
    "build_date" : "2019-10-28T20:40:44.881551Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
#

可以看到能够访问的通,至此我们的elasticsearch 安装成功。

五、创建Kibana无状态服务

kibana容器镜像选择:kibana:7.4.2

设置环境变量:
file

然后点击下一步,不用挂载任何存储,再点击下一步,为了能够让外网访问,在高级设置 中设置外网访问,并且访问方式选择 NodePort

file

file

顺便再看一下kibana无状态服务的yaml文件:

kind: Pod
apiVersion: v1
metadata:
  name: kibana-vjo4g6-566dd9fbff-c5j6t
  generateName: kibana-vjo4g6-566dd9fbff-
  namespace: gulimall
  labels:
    app: kibana
    pod-template-hash: 566dd9fbff
  annotations:
    kubesphere.io/containerSecrets: ''
spec:
  volumes:
    - name: default-token-jcbp7
      secret:
        secretName: default-token-jcbp7
        defaultMode: 420
  containers:
    - name: container-miyp7k
      image: 'kibana:7.4.2'
      ports:
        - name: tcp-5601
          containerPort: 5601
          protocol: TCP
      env:
        - name: ELASTICSEARCH_URL
          value: 'http://elasticsearch.gulimall:9200'
      resources:
        limits:
          cpu: 780m
          memory: 920Mi
        requests:
          cpu: 10m
          memory: 10Mi
      volumeMounts:
        - name: default-token-jcbp7
          readOnly: true
          mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      imagePullPolicy: IfNotPresent
  restartPolicy: Always
  terminationGracePeriodSeconds: 30
  dnsPolicy: ClusterFirst
  serviceAccountName: default
  serviceAccount: default
  nodeName: master
  securityContext: {}
  affinity: {}
  schedulerName: default-scheduler
  tolerations:
    - key: node.kubernetes.io/not-ready
      operator: Exists
      effect: NoExecute
      tolerationSeconds: 300
    - key: node.kubernetes.io/unreachable
      operator: Exists
      effect: NoExecute
      tolerationSeconds: 300
  priority: 0
  enableServiceLinks: true

相关文章:
谷粒商城-高级-35 全文检索 Elasticsearch-基础及使用 Docker 安装

为者常成,行者常至