NGINX Ingress 控制器后端协议注释如何在基于路径的路由中工作?
How NGINX Ingress controller back-end protocol annotation works in path based routing?
我目前正在我的 k8s 集群中使用 NGINX 入口控制器。我试图使端到端加密工作,并且我能够使连接一直安全到 pod。
为了一直做到HTTPS到pod,不得不用annotation
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
样本入口:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: foo-api-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
spec:
tls:
- hosts:
- foo.example.com
secretName: foo-cert
rules:
- host: foo.example.com
http:
paths:
- path: /path1
backend:
serviceName: foo-api-path1-service
servicePort: 443
- path: /path2
backend:
serviceName: foo-api-path2-service
servicePort: 443
我对这到底是怎么发生的感到困惑,因为当我们加密连接路径时,NGINX 如何进行基于路径的路由?它会在入口处解密连接并重新加密吗?另外,使用这种方法会影响性能吗?
TL;DR
does it decrypt the connection at ingress and re-encrypt it?
简而言之,是的。请看下面的解释。
说明
请求到达 Pod
的路径可以看作:
假设我们用 Ingress controller
(nginx-ingress
) 代替 Ingress
,您可以通过多种方式将您的客户端连接到 Pod
(简化) :
- 未加密:
client
-- (HTTP) --> Ingress controller
-- (HTTP) --> Service
----> Pod
- 在
Ingress controller
处加密(使用 nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
)
client
-- (HTTP) --> Ingress controller
-- (HTTPS) --> Service
--- -> Pod
- 在发生 TLS Termination 的
Ingress controller
处加密和解密:
client
-- (HTTPS) --> Ingress controller
(TLS 终止) -- (HTTP) --> Service
----> Pod
您的设置:
- 在
Ingress
控制器上加密和解密,其中 TLS Termination 发生并且 再次加密 当通过 nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
与 HTTPS 后端连接时:
client
-- (HTTPS) --> Ingress controller
(TLS终止) -- (HTTPS) --> Service
----> Pod
- 在
Pod
加密解密,其中Ingress controller
配置为SSL Passthrough:
client
-- (HTTPS) --> Ingress controller
-- (HTTPS) --> Service
----> Pod
Disclaimer!
This is only a simplified explanation. For more reference you can look at this comment:
there is a missing detail here, the SSL Passthrough traffic never reaches NGINX in the ingress controller. There is a go listener for TLS connections that just pipes the traffic to the service defined in the ingress.
有关更多参考,您可以查看类似的问题(有答案):
您还可以使用与您类似的示例设置查看这篇文章:
其他资源:
我目前正在我的 k8s 集群中使用 NGINX 入口控制器。我试图使端到端加密工作,并且我能够使连接一直安全到 pod。
为了一直做到HTTPS到pod,不得不用annotation
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
样本入口:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: foo-api-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
spec:
tls:
- hosts:
- foo.example.com
secretName: foo-cert
rules:
- host: foo.example.com
http:
paths:
- path: /path1
backend:
serviceName: foo-api-path1-service
servicePort: 443
- path: /path2
backend:
serviceName: foo-api-path2-service
servicePort: 443
我对这到底是怎么发生的感到困惑,因为当我们加密连接路径时,NGINX 如何进行基于路径的路由?它会在入口处解密连接并重新加密吗?另外,使用这种方法会影响性能吗?
TL;DR
does it decrypt the connection at ingress and re-encrypt it?
简而言之,是的。请看下面的解释。
说明
请求到达 Pod
的路径可以看作:
假设我们用 Ingress controller
(nginx-ingress
) 代替 Ingress
,您可以通过多种方式将您的客户端连接到 Pod
(简化) :
- 未加密:
client
-- (HTTP) -->Ingress controller
-- (HTTP) -->Service
---->Pod
- 在
Ingress controller
处加密(使用nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
)client
-- (HTTP) -->Ingress controller
-- (HTTPS) -->Service
--- ->Pod
- 在发生 TLS Termination 的
Ingress controller
处加密和解密:client
-- (HTTPS) -->Ingress controller
(TLS 终止) -- (HTTP) -->Service
---->Pod
您的设置:
- 在
Ingress
控制器上加密和解密,其中 TLS Termination 发生并且 再次加密 当通过nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
与 HTTPS 后端连接时:client
-- (HTTPS) -->Ingress controller
(TLS终止) -- (HTTPS) -->Service
---->Pod
- 在
Pod
加密解密,其中Ingress controller
配置为SSL Passthrough:client
-- (HTTPS) -->Ingress controller
-- (HTTPS) -->Service
---->Pod
Disclaimer!
This is only a simplified explanation. For more reference you can look at this comment:
there is a missing detail here, the SSL Passthrough traffic never reaches NGINX in the ingress controller. There is a go listener for TLS connections that just pipes the traffic to the service defined in the ingress.
有关更多参考,您可以查看类似的问题(有答案):
您还可以使用与您类似的示例设置查看这篇文章:
其他资源: