1. 问题

使用官方给出的快速搭建手册:开始使用Elastic Cloud on Kubernetes 所搭建的服务是基于https访问的,在实际应用中可能由于证书问题不方便使用,所以这里改为使用http进行访问。

2. 解决方案

将搭建es的yaml文件修改为:

apiVersion: elasticsearch.k8s.elastic.co/v1beta1
kind: Elasticsearch
metadata:
  name: quickstart
spec:
  nodeSelector:
        kubernetes.io/hostname: k8s-master
  version: 7.4.0
  nodeSets:
  - name: default
    count: 1
    config:
      node.master: true
      node.data: true
      node.ingest: false
      node.store.allow_mmap: false
  http:
    tls:
      selfSignedCertificate:
        disabled: true

如果你也不想使用账号密码访问,基本认证可以绕过启用匿名访问,添加如下内容:

spec:
  nodes:
  - nodeCount: 1
    config:
      xpack.security.authc:
          anonymous:
            username: anonymous
            roles: superuser
            authz_exception: false

同时可以通过修改svc配置将服务端口设置为NodePort模式,不再使用转发端口的形式访问:

apiVersion: v1
kind: Service
metadata:
  labels:
    common.k8s.elastic.co/type: elasticsearch
    elasticsearch.k8s.elastic.co/cluster-name: quickstart
  name: quickstart-es-nodeport
  namespace: default
spec:
  ports:
  - name: http
    nodePort: 30101
    port: 9200
    protocol: TCP
    targetPort: 9200
  selector:
    common.k8s.elastic.co/type: elasticsearch
    elasticsearch.k8s.elastic.co/cluster-name: quickstart
  type: NodePort
status:
  loadBalancer: {}

3. 效果截图

将9200端口映射为30101端口
在这里插入图片描述
通过http进行访问:http://xxx.xxx.xxx.xxx:30101
在这里插入图片描述

Logo

开源、云原生的融合云平台

更多推荐