kubernetes - 如何在 Kubernetes 集群中运行 https 安全应用程序
问题描述
我想在 https 上的 kubernetes 集群内运行我的应用程序,并通过 https 在集群外公开它。我创建pod
并暴露了端口443
。之后,我创建了一个ClusterIP
服务,它连接到 port 上的 pod443
并公开 port 443
。最后,我创建了一个ingress
连接到 port 上的服务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>
但是当我使用外部 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"
从文档
使用 backend-protocol annotations 可以指示 NGINX 应该如何与后端服务通信。(替换旧版本中的安全后端)有效值:HTTP、HTTPS、GRPC、GRPCS、AJP 和 FCGI
默认情况下,NGINXHTTP
在将请求转发到后端 pod 时使用,400 The plain HTTP request was sent to HTTPS port
因为后端 pod 正在等待HTTPS
请求。
推荐阅读
- data-structures - 处理客户订单的最佳数据结构是什么?
- python - pygame.error:混音器未初始化如何修复?
- r - 如何在 R 中的 SQLDF 中使用 LIKE 在多个数据帧中搜索文本
- android-emulator - Ubuntu 通过 avdmanager 创建 AVD 时出现路径错误
- strapi - Strapi 自定义控制器从管理 UI 执行
- php - CI 中的 PHPUnit 停滞
- c++ - C++ VSCode Mac 版本 10.15.4 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- python - Plotly Dash:选择 DataTable 中的行作为回调输出 + 过滤器
- sql-server - 将 SQL 查询转换为 SQL 函数?
- regex - 为一个非常大的文件添加一个正则表达式