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

问题描述

我想在kubernetes集群上的https上运行我的应用程序,并通过https在集群外公开它。我创建了pod并公开了端口443。之后,我创建了一个ClusterIP服务,该服务连接到端口443上的Pod,并公开了端口443。最后,我创建了一个ingress,该端口连接到端口443上的服务。我使用舵图在GKE上部署了所有这些资源。我使用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

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

默认情况下,NGINX在将请求转发到后端HTTP的后端Pod时使用400 The plain HTTP request was sent to HTTPS port,因为后端Pod期待HTTPS请求。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...