仪表板的入口配置



我从github做了nginx入口控制器教程和 公开的 Kubernetes 仪表板

kubernetes-dashboard   NodePort    10.233.53.77    <none>        443:31925/TCP   20d

已创建入口

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/ssl-passthrough: "true"
nginx.org/ssl-backends: "kubernetes-dashboard"
kubernetes.io/ingress.allow-http: "false"
name: dashboard-ingress
namespace: kube-system
spec:
tls:
- hosts:
- serverdnsname
secretName: kubernetes-dashboard-certs
rules:
- host: serverdnsname
http:
paths:
- path: /dashboard
backend:
serviceName: kubernetes-dashboard
servicePort: 443

ingress-nginx   ingress-nginx          NodePort    10.233.21.200   <none>        80:30827/TCP,443:32536/TCP   5h

https://serverdnsname:32536/dashboard 但是仪表板抛出错误

2018/01/18 14:42:51 http: TLS handshake error from ipWhichEndsWith.77:52686: tls: first record does not look like a TLS handshake

和入口控制器日志

2018/01/18 14:42:51 [error] 864#864: *37 upstream sent no valid HTTP/1.0 header while reading response header from upstream, client: 10.233.82.1, server: serverdnsname, request: "GET /dashboard HTTP/2.0", upstream: "http://ipWhichEndsWith.249:8443/dashboard", host: "serverdnsname:32536"
10.233.82.1 - [10.233.82.1] - - [18/Jan/2018:14:42:51 +0000] "GET /dashboard HTTP/2.0" 009 7 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36 OPR/49.0.2725.64" 25 0.001 [kube-system-kubernetes-dashboard-443] ipWhichEndsWith.249:8443 7 0.001 200

在我看来,它与nginx重定向到上游有关:"http://ipWhichEndsWith.249:8443/dashboard"。 尝试将控制器映像版本更新为 0.9.0-beta.19 - 没有帮助

感谢您的任何帮助。

正如您所指出的,看起来nginx正在将您的https请求代理到ipWhichEndsWith.249:8443,这是一个HTTPS端点,使用http作为协议。

您应该将以下注释添加到 PodSpec 中:

最近的

添加此注释是为了替换自 0.18.0 以来已弃用的注释

#2871 添加对 AJP 协议的支持

nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"

荒废的

此注释在 0.18.0 中已弃用,并在发布后删除 0.20.0

#3203 删除已弃用的注释 grpc 后端和安全后端

nginx.ingress.kubernetes.io/secure-backends: "true"

这应该使nginx使用https将您的请求转发到pod。

来源: https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/nginx-configuration/annotations.md#backend-protocol

文档:https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#backend-protocol

仅供代码参考。有2个gtochas。设置正确的注释,因为仪表板使用 https 并为入口使用正确的名称速度。TLS 配置是可选的。

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: dashboard-google
namespace: kube-system
annotations:
nginx.ingress.kubernetes.io/secure-backends: "true"
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
spec:
tls:
- hosts:
- kube.mydomain.com
secretName: tls-secret
rules:
- host: kube.mydomain.com
http:
paths:
- path: /
backend:
serviceName: kubernetes-dashboard
servicePort: 443

要保持此票证更新(如果用户使用 nginx 入口)以访问 Kubernetes 仪表板,您需要应用以下注释:

annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"

不要在高于image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.26.1的更高版本上使用secure-backends。它被替换为backend-protocol.

如果用户在非https端口中使用入口,例如80可以按照此处所述完成TLS终止(nging入口文档)。

带有子域的完整代码示例:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: kubernetes-dashboard-ingress
namespace: kubernetes-dashboard
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
spec:
tls:
- hosts:
- "dashboard.my.example.com"
secretName: kubernetes-dashboard-secret
rules:
- host: "dashboard.my.example.com"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: kubernetes-dashboard
port:
number: 443

希望这可以帮助像我这样的其他初学者不要花太多时间来弄清楚如何做到这一点。此外,用户应考虑面向入口控制器的外部负载均衡器配置。请记住将其设置为要转发的端口的SSL Pass-Through

更新:如果用户想要使用另一个入口提供程序,例如 Kubernetes 入口控制器文档/HAProxy Kubernetes 入口/控制器 1.4

带有注释的代码示例:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: kubernetes-dashboard-ingress
namespace: kubernetes-dashboard
annotations:
haproxy.org/server-ssl: "true"
spec:
tls:
- hosts:
- "dashboard.my.example.com"
secretName: kubernetes-dashboard-secret
rules:
- host: "dashboard.my.example.com"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: kubernetes-dashboard
port:
number: 443

用户不应忘记机密在每个命名空间中都是唯一的。

您也可以使用此处提供的掌舵图表

helm-chart/kubernetes-dashboard

然后设置您的values.yaml文件以覆盖ingress部分,例如启用它,并添加主机可用。

这是对我有用的仪表板的入口。

api版本: networking.k8s.io/v1 种类:入口 元数据: 名称:Kubernetes-dashboard 命名空间:库贝系统 附注: nginx.ingress.kubernetes.io/backend-protocol:"HTTPS" nginx.ingress.kubernetes.io/rewrite-target:/$2 nginx.ingress.kubernetes.io/configuration-snippet: | 重写 ^(/仪表板)$ $1/重定向; 规范: 入口类名: nginx TLS: -主机: - yourdomain.com secretName: kubernetes-dashboard-tls 规则: - 主持人:yourdomain.com http: 路径: - 路径:/dashboard(/|$)(.*) 路径类型:前缀 后端: 服务: 名称:Kubernetes-dashboard 港口: 编号: 443

这应该在部署本身通过设置SERVER_BASEPATH和SERVER_REWRITEBASEPATH来修复,入口级别的重定向将是平滑的,

部署文件

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: osd-deployment
spec:
replicas: 1
selector:
matchLabels:
app: osd
template:
metadata:
labels:
app: osd
spec:
containers:
- name: osd
imagePullPolicy: Never
image: 
env:
- name: server.ssl.enabled
value: "false"
- name: OPENSEARCH_HOSTS
value: http://opensearch-service:9200
- name: SERVER_BASEPATH
value: /dashboard
- name: SERVER_REWRITEBASEPATH
value: "true"              
ports:
- containerPort: 5601
name: http

服务文件:

---
apiVersion: v1
kind: Service
metadata:
name: osd-service
spec:
selector:
app: osd
type: ClusterIP
ports:
- name: port5601
protocol: TCP
port: 5601
targetPort: 5601

入口文件:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: osd-ingress
annotations:
nginx.ingress.kubernetes.io/backend-protocol: HTTP
nginx.ingress.kubernetes.io/proxy-buffer-size: 128k
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"  
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /dashboard
pathType: Prefix
backend:
service:
name: osd-service
port:
number: 5601  

相关内容

  • 没有找到相关文章

最新更新