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

Roh*_*ara 3 kubernetes kubernetes-ingress nginx-ingress

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

当我通过 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>
Run Code Online (Sandbox Code Playgroud)

但是当我使用外部 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>
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚出了什么问题。我怀疑这与入口控制器配置有关。请帮我解决这个问题。

Arg*_*dhu 6

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

nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
Run Code Online (Sandbox Code Playgroud)

来自文档

使用后端协议注释可以指示 NGINX 应如何与后端服务通信。(替换旧版本中的安全后端)有效值:HTTP、HTTPS、GRPC、GRPCS、AJP 和 FCGI

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