我想在https上的kubernetes集群内运行我的应用程序,并通过https在集群外公开它。我创建了pod
并公开了端口443
。之后,我创建了一个ClusterIP
服务,该服务连接到端口443
上的pod,并公开端口443
。最后,我创建了一个ingress
,它连接到端口443
上的服务。我使用GKE上的舵图部署了所有这些资源。我使用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>
但当我使用外部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"
从文档
使用后端协议注释可以指示NGINX应该与后端服务通信。(替换安全后端在旧版本中(有效值:HTTP、HTTPS、GRPC、GRPCS、AJP和FCGI
默认情况下,NGINX在将请求转发到后端pod时使用HTTP
,这会导致400 The plain HTTP request was sent to HTTPS port
,因为后端pod需要HTTPS
请求。