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