简体   繁体   English

kubernetes单模式无法连接elasticsearch和kibana

[英]Can't connect elasticsearch and kibana on kubernetes single mode

I try to run elasticsearch and kibana on kubernetes.我尝试在 kubernetes 上运行 elasticsearch 和 kibana。 I ran:我跑了:

kubectl run elasticsearch --image=elasticsearch:6.6.1 --env="discovery.type=single-node" --port=9200 --port=9300
kubectl run kibana --image=kibana:6.6.1 --port=5601

then I ran $kubectl proxy ,然后我运行了$kubectl proxy

http://localhost:$IP_FROM_KUBECTL_PROXY(usually 8081)/api/v1/namespaces/default/pods/$POD_NAME/proxy/

When I entered to elasticsearch pod, everything looks fine, but when I entered to kibana, the app didn't work (I see "Kibana server is not ready yet" for infinity).当我进入 elasticsearch pod 时,一切看起来都很好,但是当我进入 kibana 时,该应用程序不起作用(我看到无穷大的“Kibana 服务器尚未准备好”)。

The logs of kibana are the following: kibana的日志如下:

{"type":"log","@timestamp":"2019-03-02T10:38:47Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"No living connections"}
{"type":"log","@timestamp":"2019-03-02T10:38:49Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"Unable to revive connection: http://elasticsearch:9200/"}

This is kibana.yml on kibana pod:这是 kibana pod 上的 kibana.yml:

Default Kibana configuration from kibana-docker.来自 kibana-docker 的默认 Kibana 配置。

server.name: kibana
server.host: "0"
elasticsearch.url: http://elasticsearch:9200
xpack.monitoring.ui.container.elasticsearch.enabled: true

I'm pretty new with Kubernetes, and I can't figure out why they can't talk one to another.我对 Kubernetes 很陌生,我不明白为什么他们不能互相交谈。

This Kibana log entry explains to you what the problem is:此 Kibana 日志条目向您解释了问题所在:

{"type":"log","@timestamp":"2019-03-02T10:38:49Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"Unable to revive connection: http://elasticsearch:9200/"} {"type":"log","@timestamp":"2019-03-02T10:38:49Z","tags":["warning","elasticsearch","admin"],"pid":1, "message":"无法恢复连接:http://elasticsearch:9200/"}

Problem: Naming your pod elasticsearch is not enough for kubernetes.问题:对 Kubernetes 来说,命名你的 pod elasticsearch 是不够的。

You have a few solutions to fix it depending on the situation:根据情况,您有几种解决方案来修复它:

  1. Create a service as Amityo has suggested.按照Amityo 的建议创建服务。 This is enough if kibana and elasticsearch are running in the same namespace.如果 kibana 和 elasticsearch 在同一个命名空间中运行,这就足够了。

  2. If kibana and elasticsearch are running in different namespaces you'll need to use the full DNS name for service: elasticsearch.my-namespace.svc.cluster.local如果 kibana 和 elasticsearch 在不同的命名空间中运行,您需要使用完整的 DNS 名称来提供服务:elasticsearch.my-namespace.svc.cluster.local

  3. If you run elasticsearch and kibana in the same pod.如果您在同一个 pod 中运行 elasticsearch 和 kibana。 Then localhost:9200 will be enough to be able to query.然后 localhost:9200 就足以能够查询了。

  4. For your current situation.对于你现在的情况。 When elasticsearch is running you can use as ELASTICSEARCH_URL the pod DNS name: 1-2-3-4.default.pod.cluster.local when 1-2-3-4 is IP address of pod with dots replaced by dashes.当elasticsearch 运行时,您可以使用 ELASTICSEARCH_URL pod DNS 名称:1-2-3-4.default.pod.cluster.local 当 1-2-3-4 是 pod 的 IP 地址时,点由破折号代替。

You can define the hostname when you create a Pod definition for elasticsearch using the following YAML:您可以在使用以下 YAML 为 elasticsearch 创建 Pod 定义时定义主机名:

apiVersion: v1
kind: Pod
metadata:
  name: elasticsearch
  labels:
    name: elasticsearch-single
spec:
  hostname: elasticsearch
  subdomain: for-kibana
  containers:
  - image: elasticsearch:6.6.1
    name: elasticsearch

Then you will be able to use as ELASTICSEARCH_URL the pod DNS name: elasticsearch.for-kibana.default.svc.cluster.local service.然后您将能够使用 ELASTICSEARCH_URL pod DNS 名称:elasticsearch.for-kibana.default.svc.cluster.local 服务。

All information you can find on kubernetes doc here您可以在此处在 kubernetes doc 上找到的所有信息

Please note: According to official docs the Env variable ELASTICSEARCH_URL is deprecated in newer elasticsearch versions, more details see here请注意:根据官方文档,Env 变量 ELASTICSEARCH_URL 在较新的 elasticsearch 版本中已弃用,更多详细信息请参见此处

In kubernetes pods communicate with Services.在 kubernetes 中,pod 与服务通信。 You will need to define a service that selects your pod (with selector).您将需要定义一个服务来选择您的 pod(使用选择器)。

for example:例如:

kind: Service
apiVersion: v1
metadata:
  name: elasticsearch
spec:
  selector:
    app: elasticsearch
  ports:
  - protocol: TCP
    port: 9200
    targetPort: 9200

Read more about services here and about labels here 在这里阅读更多关于服务和标签的信息

We usually define the pods as yml files and add the labels there, but if you want to use kubectl run you can add labels with -l我们通常将 pod 定义为 yml 文件并在那里添加标签,但是如果您想使用kubectl run您可以使用-l添加标签

  -l, --labels='': Comma separated labels to apply to the pod(s). Will override previous values.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM