简体   繁体   English

如何在 Kubernetes 中为 Kibana 设置入口

[英]How do I setup ingress for Kibana in Kubernetes

I have just installed an EFK stack on my Kubernetes cluster using the guide on https://medium.com/@timfpark/efk-logging-on-kubernetes-on-azure-4c54402459c4我刚刚使用https://medium.com/@timfpark/efk-logging-on-kubernetes-on-azure-4c54402459c4上的指南在我的 Kubernetes 集群上安装了一个 EFK 堆栈

I have it working when accessing it through the proxy as stated in the guide on我在通过代理访问它时让它工作,如指南中所述

http://localhost:8001/api/v1/namespaces/kube-system/services/kibana-logging/proxy http://localhost:8001/api/v1/namespaces/kube-system/services/kibana-logging/proxy

However, I want it to work through my existing ingress controller so I have created a new ingress rule using the yaml below:但是,我希望它通过我现有的入口控制器工作,所以我使用下面的 yaml 创建了一个新的入口规则:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
  generation: 2
  labels:
    app: kibana
  name: kibana
  namespace: kube-system
spec:
  rules:
  - host: kibana.dev.example1.com
    http:
      paths:
      - backend:
          serviceName: kibana-logging
          servicePort: 5601
        path: /
status:
  loadBalancer:
    ingress:
    - {}

To my service which runs as:对于我的服务,它运行为:

apiVersion: v1
kind: Service
metadata:
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
    k8s-app: kibana-logging
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: Kibana
  name: kibana-logging
  namespace: kube-system
spec:
  clusterIP: X.X.195.49
  ports:
  - port: 5601
    protocol: TCP
    targetPort: ui
  selector:
    k8s-app: kibana-logging
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

However, when I try and access my URL: http://kibana.dev.example1.com但是,当我尝试访问我的 URL 时: http://kibana.dev.example1.com : http://kibana.dev.example1.com

I get: {"statusCode":404,"error":"Not Found","message":"Not Found"}我得到: {"statusCode":404,"error":"Not Found","message":"Not Found"}

If I try and access: http://kibana.dev.example1.com/app/kibana#如果我尝试访问: http://kibana.dev.example1.com/app/kibana# : http://kibana.dev.example1.com/app/kibana#

I get: "Kibana did not load properly. Check the server output for more information."我得到:“Kibana 没有正确加载。检查服务器输出以获取更多信息。”

After looking through the logs for both Kibana pod and ingress pod and comparing the results between a successful request through the proxy and an unsuccessful request through the ingress I can see that...在查看 Kibana pod 和 ingress pod 的日志并比较通过代理的成功请求和通过入口的不成功请求之间的结果后,我可以看到......

for hitting /击球 /

"GET / HTTP/1.1" 200 197 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15" 491 0.003 [kube-system-kibana-logging-5601] X.X.22.204:5601 197 0.003 200 6101a7003003d34636d2012e53c23ca7
"GET /api/v1/namespaces/kube-system/services/kibana-logging/proxy/app/kibana HTTP/1.1" 404 85 "http://kibana.dev.example1.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15" 612 0.003 [kube-system-kibana-logging-5601] X.X.22.204:5601 85 0.003 404 5809ac2b33d3e23b200b13c9971d8520

for hitting /app/kibana#用于点击 /app/kibana#

"GET /app HTTP/1.1" 404 85 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15" 470 0.003 [kube-system-kibana-logging-5601] X.X.22.204:5601 85 0.003 404 54a4abe0cae6d3d4298847a0db0786d6
"GET /app/kibana HTTP/1.1" 200 13301 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15" 477 0.041 [kube-system-kibana-logging-5601] X.X.22.204:5601 13272 0.040 200 6cb7e7698f5c72e0cd06b3408d8d4673
"GET /api/v1/namespaces/kube-system/services/kibana-logging/proxy/bundles/kibana.style.css?v=16627 HTTP/1.1" 404 85 "https://kibana.dev.example1.com/app/kibana" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15" 576 0.004 [kube-system-kibana-logging-5601] X.X.22.204:5601 85 0.004 404 0b825f03c36c2225ab082c2a0bab15f4

When hitting through the proxy most of these requests return 302s rather than 404s.当通过代理访问时,这些请求中的大多数返回 302s 而不是 404s。 Can the ingress not access these URLs in namespace kube-system?入口不能访问命名空间 kube-system 中的这些 URL 吗?

Am I missing something obvious here - maybe hitting the wrong Kibana URL?我是否在这里遗漏了一些明显的东西 - 也许打错了 Kibana URL? I've done a lot of googling and can't find anything similar.我已经做了很多谷歌搜索,找不到类似的东西。

Turns out the problem was with the kibana configuration.原来问题出在 kibana 配置上。

In the kibana deployment yaml there is an environment variable called SERVER_BASEPATH which is set to point at the kibana service proxy.在 kibana 部署 yaml 中有一个名为SERVER_BASEPATH的环境变量,它被设置为指向 kibana 服务代理。 This was causing the URL to be rewritten each time I tried to access the endpoint externally.这导致每次我尝试从外部访问端点时都会重写 URL。

If you comment out this variable and it's value and redeploy kibana then it should work by just hitting the ingress address.如果您注释掉此变量及其值并重新部署 kibana,那么它应该只需点击入口地址即可工作。

eg http://kibana.dev.example1.com/例如http://kibana.dev.example1.com/

turns out following environment variables needs to be set in order to expose kibana through ingress:事实证明,需要设置以下环境变量才能通过 ingress 公开 kibana:

add following in env in kibana deployment.yaml:在 kibana deployment.yaml 的env中添加以下内容:

        - name: ELASTICSEARCH_HOSTS
          value: "http://10.20.30.40:9200"
        - name: SERVER_BASEPATH
          value: "/kibana"
        - name: SERVER_REWRITEBASEPATH
          value: "true"
        - name: SERVER_PUBLICBASEURL
          value: "https://my.domain.com/kibana"

then use following to expose it over ingress:然后使用以下内容在入口处公开它:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  namespace: elastic
  name: gateway-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - host: my.domain.com
      http: 
        paths:
          - path: /kibana
            backend:
              serviceName: kibana
              servicePort: 5601

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

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