无法访问 Ubuntu 上的 kubernetes 集群中的 Kibana 仪表板服务

Unable to access Kibana dashboard service in kubernetes cluser on Ubuntu

我在尝试在本地设置 fluentd-elasticsearch 时尝试访问 Kibana 仪表板。这是我遵循的link。我检查了 Kibana 的 pod 日志。它显示以下错误:

{"type":"log","@timestamp":"2018-09-19T21:45:42Z","tags":["warning","config","deprecation"],"pid":1,"message":"You should set server.basePath along with server.rewriteBasePath. Starting in 7.0, Kibana will expect that all requests start with server.basePath rather than expecting you to rewrite the requests in your reverse proxy. Set server.rewriteBasePath to false to preserve the current behavior and silence this warning."}
root@mTrainer3:/logging# kubectl logs kibana-logging-66d577d965-mbbg5 -n kube-system
{"type":"log","@timestamp":"2018-09-19T21:45:42Z","tags":["warning","config","deprecation"],"pid":1,"message":"You should set server.basePath along with server.rewriteBasePath. Starting in 7.0, Kibana will expect that all requests start with server.basePath rather than expecting you to rewrite the requests in your reverse proxy. Set server.rewriteBasePath to false to preserve the current behavior and silence this warning."}
{"type":"log","@timestamp":"2018-09-19T21:46:08Z","tags":["status","plugin:kibana@6.4.1","info"],"pid":1,"state":"green","message":"Status changed from uninitialized to green - Ready","prevState":"uninitialized","prevMsg":"uninitialized"}

有人可以建议我如何解决这个问题吗?

讨论后更清楚似乎是错误的地方。

您正在使用没有负载平衡器的本地集群。您必须设置入口或使用 NodePort 作为服务类型。我将描述使用 NodePort 的解决方案。要采取的两个步骤:

  1. 修改kibana-deployment.yaml,删除env下的以下内容:
- name: SERVER_BASEPATH
  value: /api/v1/namespaces/kube-system/services/kibana-logging/proxy

所以你 kibana-deployment.yaml 看起来像:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kibana-logging
  namespace: kube-system
  labels:
    k8s-app: kibana-logging
    kubernetes.io/cluster-service: "true"
    addonmanager.kubernetes.io/mode: Reconcile
spec:
  replicas: 1
  selector:
  matchLabels:
    k8s-app: kibana-logging
  template:
    metadata:
      labels:
        k8s-app: kibana-logging
      annotations:
        seccomp.security.alpha.kubernetes.io/pod: 'docker/default'
    spec:
      containers:
      - name: kibana-logging
        image: docker.elastic.co/kibana/kibana-oss:6.3.2
        resources:
          # need more cpu upon initialization, therefore burstable class
          limits:
            cpu: 1000m
          requests:
            cpu: 100m
        env:
          - name: ELASTICSEARCH_URL
            value: http://elasticsearch-logging:9200
        ports:
        - containerPort: 5601
          name: ui
          protocol: TCP
  1. 修改kibana-service.yaml设置服务类型为NodePort:
apiVersion: v1
kind: Service
metadata:
  name: kibana-logging
  namespace: kube-system
  labels:
    k8s-app: kibana-logging
    kubernetes.io/cluster-service: "true"
    addonmanager.kubernetes.io/mode: Reconcile
    kubernetes.io/name: "Kibana"
spec:
  type: NodePort
  ports:
  - port: 5601
    protocol: TCP
    targetPort: ui
    nodePort: 30601
  selector:
    k8s-app: kibana-logging

然后执行

kubectl apply -f kibana-deployment.yaml
kubectl apply -f kibana-service.yaml

Kibana 应该可以在 http://<clusterip>:30601

访问

背景

您将直接访问 http://clusterip:30601 而无需给定的基本路径。所以必须删除它,以便 kibana 使用 / 作为基本路径。否则它将尝试将基本路径 /api/v1/[...] 附加到您的 url。想测试的可以试试

This comment from an elastic search guy mentions,如果要使用 /.

,则必须完全删除 base_path

修改服务为NodePort是必要的,因为K8s默认不发布端口。我刚刚在 上回答了类似的问题。

原答案(错误)

在您链接的回购中,我可以看到 kibana-deployment.yaml 必须设置环境变量:

env:
  - name: ELASTICSEARCH_URL
    value: http://elasticsearch-logging:9200
  - name: SERVER_BASEPATH
    value: /api/v1/namespaces/kube-system/services/kibana-logging/proxy

你设置好了吗?

假设您有一个直接连接到 kibana 实例的入口、负载均衡器或 NodePort,以便您希望使用 http://yourserver:9200/ 直接访问它。那么 SERVER_BASEPATH 就是 /

或者,您也可以通过指定环境变量来指定 Kibana 重写 server basepath。

修改 kibana-deployment.yaml 以添加以下内容。

- name: SERVER_REWRITEBASEPATH
  value: "true"

现在申请: kubectl apply -f kibana-deployment.yaml

microk8s 上进行了测试,在 kubectl proxy

上运行良好

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