Kibana 部署到 kubernetes 集群 returns 404
Kibana deployed to kubernetes cluster returns 404
我已将 kibana 作为 StatefulSet 部署到 kubernetes 集群。但是,当我的浏览器指向 kibana 时,它 returns {"statusCode":404,"error":"Not Found","message":"Not Found"}。任何建议和见解表示赞赏。这是我在浏览器中使用 http://app.domain.io/kibana
访问应用程序时在 pod 中看到的日志
{"type":"response","@timestamp":"2019-01-29T04:18:50Z","tags":[],"pid":1,"method":"get","statusCode":404,"req":{"url":"/kibana","method":"get","headers":{"x-forwarded-for":"[IP]","x-forwarded-proto":"https","x-forwarded-port":"443","host":"[host]","x-amzn-trace-id":"Root=1-5c4fd42a-1261c1e0474144902a2d6840","cache-control":"max-age=0","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.9,zh-CN;q=0.8,zh-TW;q=0.7,zh;q=0.6,ko;q=0.5"},"remoteAddress":"[IP]","userAgent":"10.0.2.185"},"res":{"statusCode":404,"responseTime":19,"contentLength":9},"message":"GET /kibana 404 19ms - 9.0B"}
apiVersion: v1
kind: Service
metadata:
name: svc-kibana
labels:
app: app-kibana
spec:
selector:
app: app-kibana
# tier: database
ports:
- name: kibana
protocol: TCP
port: 8080
targetPort: 5601
clusterIP: None # Headless
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: kibana
spec:
serviceName: "svc-kibana"
podManagementPolicy: "Parallel" # Default is OrderedReady
replicas: 1 # Default is 1
selector:
matchLabels:
app: app-kibana # Has to match .spec.template.metadata.labels
template:
metadata:
labels:
app: app-kibana # Has to match .spec.selector.matchLabels
spec:
terminationGracePeriodSeconds: 10
containers:
- name: kibana
securityContext:
capabilities:
add:
- IPC_LOCK
- SYS_RESOURCE
image: kibana:6.5.4
imagePullPolicy: Always
env:
- name: ELASTICSEARCH_URL
value: http://svc-elasticsearch:9200
- name: SERVER_BASEPATH
value: /api/v1/namespaces/default/services/svc-kibana/proxy
ports:
- containerPort: 5601
name: kibana
protocol: TCP
这是来自 AWS ALB 的健康检查:
{"type":"response","@timestamp":"2019-01-29T06:30:53Z","tags":[],"pid":1,"method":"get","statusCode":200,"req":{"url":"/app/kibana","method":"get","headers":{"host":"[IP]:5601","connection":"close","user-agent":"ELB-HealthChecker/2.0","accept-encoding":"gzip, compressed"},"remoteAddress":"[IP]","userAgent":"[IP]"},"res":{"statusCode":200,"responseTime":27,"contentLength":9},"message":"GET /app/kibana 200 27ms - 9.0B"}
我尝试删除 ENV 值并使用安装在 /etc/kibana/kibana.yml 上的 ConfigMap 和以下配置但无济于事:
apiVersion: v1
kind: ConfigMap
metadata:
creationTimestamp: "2019-01-29T02:12:55Z"
name: kibana-config
namespace: default
resourceVersion: "4178388"
selfLink: /api/v1/namespaces/default/configmaps/kibana-config
uid: 63b10866-236b-11e9-a14d-482ae31e6a94
data:
kibana.yml: |+
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://svc-elasticsearch:9200"
kibana.index: ".kibana"
logging.silent: false
logging.quiet: false
logging.verbose: true
- name: SERVER_BASEPATH
value: /api/v1/namespaces/default/services/svc-kibana/proxy
是导致您出现问题的错误设置,因为 server.basePath
被记录为
Enables you to specify a path to mount Kibana at if you are running behind a proxy. Use the server.rewriteBasePath
setting to tell Kibana if it should remove the basePath from requests it receives, and to prevent a deprecation warning at startup. This setting cannot end in a slash (/).
因此您将不得不使用 /api/v1/namespaces/default/services/svc-kibana/proxy/app/kibana
,因为您没有覆盖 server.defaultRoute: /app/kibana
。我不知道为什么 ELB 健康检查只返回 9 个字节的内容,但你可能想使用 /api/status
作为它的健康检查无论如何
在我将以下内容添加到 Kibana 配置后,它现在可以工作了:
server.basePath: "/my-kibana"
server.rewriteBasePath: true
感谢 Matthew L Daniel,我已将健康检查切换为 /my-kibana/api/status
我在 kubernetes 集群中遇到了同样的问题,其中 kibana 运行 在 nginx 代理后面。
DNS: https://my-url/dashboard
Nginx conf:
location /dashboard/ {
rewrite ^/dashboard/(.*) / break;
proxy_pass http://kibana:5601/;
在 kibana.yml
中添加 Kok How teh 建议的参数后
kibana.yml:
server.name: kibana
server.host: "0"
elasticsearch.url: http://elasticsearch:9200
server.basePath: "/dashboard" #this line
能够解决重定向问题。
我已将 kibana 作为 StatefulSet 部署到 kubernetes 集群。但是,当我的浏览器指向 kibana 时,它 returns {"statusCode":404,"error":"Not Found","message":"Not Found"}。任何建议和见解表示赞赏。这是我在浏览器中使用 http://app.domain.io/kibana
访问应用程序时在 pod 中看到的日志{"type":"response","@timestamp":"2019-01-29T04:18:50Z","tags":[],"pid":1,"method":"get","statusCode":404,"req":{"url":"/kibana","method":"get","headers":{"x-forwarded-for":"[IP]","x-forwarded-proto":"https","x-forwarded-port":"443","host":"[host]","x-amzn-trace-id":"Root=1-5c4fd42a-1261c1e0474144902a2d6840","cache-control":"max-age=0","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.9,zh-CN;q=0.8,zh-TW;q=0.7,zh;q=0.6,ko;q=0.5"},"remoteAddress":"[IP]","userAgent":"10.0.2.185"},"res":{"statusCode":404,"responseTime":19,"contentLength":9},"message":"GET /kibana 404 19ms - 9.0B"}
apiVersion: v1
kind: Service
metadata:
name: svc-kibana
labels:
app: app-kibana
spec:
selector:
app: app-kibana
# tier: database
ports:
- name: kibana
protocol: TCP
port: 8080
targetPort: 5601
clusterIP: None # Headless
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: kibana
spec:
serviceName: "svc-kibana"
podManagementPolicy: "Parallel" # Default is OrderedReady
replicas: 1 # Default is 1
selector:
matchLabels:
app: app-kibana # Has to match .spec.template.metadata.labels
template:
metadata:
labels:
app: app-kibana # Has to match .spec.selector.matchLabels
spec:
terminationGracePeriodSeconds: 10
containers:
- name: kibana
securityContext:
capabilities:
add:
- IPC_LOCK
- SYS_RESOURCE
image: kibana:6.5.4
imagePullPolicy: Always
env:
- name: ELASTICSEARCH_URL
value: http://svc-elasticsearch:9200
- name: SERVER_BASEPATH
value: /api/v1/namespaces/default/services/svc-kibana/proxy
ports:
- containerPort: 5601
name: kibana
protocol: TCP
这是来自 AWS ALB 的健康检查:
{"type":"response","@timestamp":"2019-01-29T06:30:53Z","tags":[],"pid":1,"method":"get","statusCode":200,"req":{"url":"/app/kibana","method":"get","headers":{"host":"[IP]:5601","connection":"close","user-agent":"ELB-HealthChecker/2.0","accept-encoding":"gzip, compressed"},"remoteAddress":"[IP]","userAgent":"[IP]"},"res":{"statusCode":200,"responseTime":27,"contentLength":9},"message":"GET /app/kibana 200 27ms - 9.0B"}
我尝试删除 ENV 值并使用安装在 /etc/kibana/kibana.yml 上的 ConfigMap 和以下配置但无济于事:
apiVersion: v1
kind: ConfigMap
metadata:
creationTimestamp: "2019-01-29T02:12:55Z"
name: kibana-config
namespace: default
resourceVersion: "4178388"
selfLink: /api/v1/namespaces/default/configmaps/kibana-config
uid: 63b10866-236b-11e9-a14d-482ae31e6a94
data:
kibana.yml: |+
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://svc-elasticsearch:9200"
kibana.index: ".kibana"
logging.silent: false
logging.quiet: false
logging.verbose: true
- name: SERVER_BASEPATH
value: /api/v1/namespaces/default/services/svc-kibana/proxy
是导致您出现问题的错误设置,因为 server.basePath
被记录为
Enables you to specify a path to mount Kibana at if you are running behind a proxy. Use the
server.rewriteBasePath
setting to tell Kibana if it should remove the basePath from requests it receives, and to prevent a deprecation warning at startup. This setting cannot end in a slash (/).
因此您将不得不使用 /api/v1/namespaces/default/services/svc-kibana/proxy/app/kibana
,因为您没有覆盖 server.defaultRoute: /app/kibana
。我不知道为什么 ELB 健康检查只返回 9 个字节的内容,但你可能想使用 /api/status
作为它的健康检查无论如何
在我将以下内容添加到 Kibana 配置后,它现在可以工作了:
server.basePath: "/my-kibana"
server.rewriteBasePath: true
感谢 Matthew L Daniel,我已将健康检查切换为 /my-kibana/api/status
我在 kubernetes 集群中遇到了同样的问题,其中 kibana 运行 在 nginx 代理后面。
DNS: https://my-url/dashboard
Nginx conf:
location /dashboard/ {
rewrite ^/dashboard/(.*) / break;
proxy_pass http://kibana:5601/;
在 kibana.yml
中添加 Kok How teh 建议的参数后kibana.yml:
server.name: kibana
server.host: "0"
elasticsearch.url: http://elasticsearch:9200
server.basePath: "/dashboard" #this line
能够解决重定向问题。