Jun*_*aed 2 tomcat kubernetes kubernetes-ingress nginx-ingress
我有一个 Java 应用程序在 tomcat 服务器(位于 pod 内)内运行,该应用程序配置为使用 https。我正在使用 nginx 入口。问题是,nginx 入口正在终止 SSL 并仅将纯 http 转发到 tomcat 服务器(实际上是到 pod)。由于 tomcat 服务器配置为仅使用 HTTPS,因此它不接受流量。
以下不起作用:
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
Run Code Online (Sandbox Code Playgroud)
最后我找到了答案:
我必须添加以下两行:
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
Run Code Online (Sandbox Code Playgroud)
所以入口是这样的(我还添加了一些评论来描述并显示我尝试过但不起作用的选项,这样你就不会浪费时间):
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-resource-staging
namespace: staging-space
annotations:
kubernetes.io/ingress.class: nginx #You may deploy any number of ingress controllers within a cluster. When you create an ingress, you should annotate each ingress with the appropriate ingress.class to indicate which ingress controller should be used if more than one exists within your cluster.
#If you do not define a class, your cloud provider may use a default ingress controller.
#nginx.ingress.kubernetes.io/ssl-passthrough: "true"
##Following 2 lines are important, otherwise the SSL is terminated at the ingress level and the
## traffic sent to the service is plain http and then tomcat complains that the host and port combination
## needs https connection (in the tomcat server we have enabled the HTTPS internally)
## We want to forward the HTTPS traffic to the pods
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
spec:
#tls:
# - hosts:
# - yourhost.com
rules:
- host: yourhost.com
http:
paths:
- pathType: Prefix
path: /
backend:
service:
name: my-app-service
port:
#number: 8080
number: 8443
Run Code Online (Sandbox Code Playgroud)
默认情况下禁用 SSL 直通,并且需要使用 --enable-ssl-passthrough 标志启动控制器。
因此,如果您想使用注释 nginx.ingress.kubernetes.io/ssl-passthrough,则需要使用 --enable-ssl-passthrough 标志启动 Nginx Ingress Controller
此外,由于 SSL 直通适用于 OSI 模型 (TCP) 的第 4 层,而不是第 7 层 (HTTP),因此使用 SSL 直通会使 Ingress 对象上设置的所有其他注释无效。
编辑 :
如果您对入口控制器使用入口注释 nginx.ingress.kubernetes.io/ssl-passthrough 和 --enable-ssl-passthrough=true 标志,则 SSL 终止将在您的 Tomcat Server Pod 上发生。因此,您的客户端浏览器收到的 SSL 服务器证书就是您的 Tomcat SSL 服务器证书。在这种情况下,您的客户端浏览器将必须信任 Tomcat SSL 服务器证书。此 SSL 直通发生在第 4 层 TCP,因此 NGINX 入口控制器不会解密来自客户端浏览器的 SSL 流量,它只是将其传递到 Tomcat Server Pod。
如果您仅使用注释 nginx.ingress.kubernetes.io/backend-protocol: "HTTPS",那么第一个 SSL 终止将在您的入口控制器上发生。因此,您的客户端浏览器收到的 SSL 服务器证书是您的 Nginx Ingress Controller SSL 服务器证书,您的客户端浏览器必须信任它。然后从 Nginx Ingress Controller 到 Tomcat Pod 的通信使用另一种 SSL 加密。在这种情况下,您的 Nginx 入口控制器必须信任 Tomcat SSL 服务器证书,并且您拥有双重 SSL 加密和解密。
如果您使用注释 nginx.ingress.kubernetes.io/force-ssl-redirect: "true" 那么您的所有 http 请求都将使用 308 重定向 http 代码重定向到 https。您调用的是 http:// 还是 https:// ?
以下是代码和文档链接
https://github.com/kubernetes/ingress-nginx/blob/master/rootfs/etc/nginx/lua/lua_ingress.lua
https://github.com/openresty/lua-nginx-module
http://nginx.org/en/docs/http/ngx_http_proxy_module.html
当您在入口资源中进行更改时,检查 /etc/nginx/nginx.conf 在 nginx 控制器 pod 内如何变化
| 归档时间: |
|
| 查看次数: |
5221 次 |
| 最近记录: |