如何 运行 kubernetes 集群中的 https 安全应用程序

How to run a https secured app in kubernetes cluster

我想 运行 我的应用程序在 https 上的 kubernetes 集群内,并通过 https 将其暴露在集群外。我创建了 pod 并公开了端口 443。之后,我创建了一个 ClusterIP 服务,它连接到端口 443 上的 pod 并公开端口 443。最后,我创建了一个 ingress 连接到端口 443 上的服务。我在 GKE 上使用 helm chart 部署了所有这些资源。我使用 NGINX Ingress 控制器。您可以找到图表 here.

当我通过 https 在集群内部访问应用程序时,它工作正常。

curl https://my-nginx.https-app-64-production --cacert /etc/nginx/ssl/tls.crt
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

但是,当我使用外部 url 访问它时,出现以下错误。

curl https://staging.vs-creator.iotcrawler.eu/
<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx/1.9.1</center>
</body>
</html>

我不知道出了什么问题。我怀疑这与入口控制器配置有关。请帮我解决这个问题。

在入口资源中使用以下注释

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

来自docs

Using backend-protocol annotations is possible to indicate how NGINX should communicate with the backend service. (Replaces secure-backends in older versions) Valid Values: HTTP, HTTPS, GRPC, GRPCS, AJP and FCGI

默认情况下,NGINX 在将请求转发到后端 pod 时使用 HTTP,这会导致 400 The plain HTTP request was sent to HTTPS port,因为后端 pod 需要 HTTPS 请求。