GKE配置502错误网关上的Ingress-nginx

如何解决GKE配置502错误网关上的Ingress-nginx

我正在尝试通过ingress-nginx和Google云负载均衡器公开GKE集群中的mlflow模型。

各个部署的服务配置如下:

apiVersion: v1
kind: Service
metadata:
  name: model-inference-service
  labels:
    app: inference
spec:
  ports:
  - port: 5555
    targetPort: 5555
  selector:
    app: inference

使用kubectl port-forward service/model-inference-service 5555:5555将此服务转发到localhost时,可以使用以下script将测试图像发送到api端点,从而成功查询模型。

请求发送到的URL为http://127.0.0.1:5555/invocations这按预期工作,因此我假设运行运行Pod的部署公开了模型,并且相应的clusterIP服务model-inference-service已正确配置。

接下来,我通过这样做将ingress-nxinx安装到集群中

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm install my-release ingress-nginx/ingress-nginx

入口的配置如下(我怀疑错误一定在这里吗?):

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
#    nginx.ingress.kubernetes.io/rewrite-target: /invocations
  name: inference-ingress
  namespace: default
  labels:
    app: inference
spec:
  rules:
    - http:
        paths:
          - path: /invocations
            backend:
              serviceName: model-inference-service
              servicePort: 5555

入口控制器pod运行成功:

my-release-ingress-nginx-controller-6758cc8f45-fwtw7   1/1     Running   0          3h33m

在GCP控制台中,我可以看到负载均衡器也已成功创建,并且可以获取其IP。

当使用我之前向Rest api端点发出请求(以前该服务已转发到localhost)但现在使用负载均衡器的ip的测试脚本时,出现502 Bad Gateway错误:>

现在的网址如下:http://34.90.4.0:80/invocations

Traceback (most recent call last):
  File "test_inference.py",line 80,in <module>
    run()
  File "//anaconda3/lib/python3.7/site-packages/click/core.py",line 829,in __call__
    return self.main(*args,**kwargs)
  File "//anaconda3/lib/python3.7/site-packages/click/core.py",line 782,in main
    rv = self.invoke(ctx)
  File "//anaconda3/lib/python3.7/site-packages/click/core.py",line 1066,in invoke
    return ctx.invoke(self.callback,**ctx.params)
  File "//anaconda3/lib/python3.7/site-packages/click/core.py",line 610,in invoke
    return callback(*args,**kwargs)
  File "test_inference.py",line 76,in run
    print(score_model(data_path,host,port).text)
  File "test_inference.py",line 54,in score_model
    status_code=response.status_code,text=response.text
Exception: Status Code 502. <html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.19.1</center>
</body>
</html>

在浏览器中访问相同的URL时,它说:

502 Bad Gateway
nginx/1.19.1

入口控制器状态的日志:

2020/08/26 16:06:45 [warn] 86#86: *42282 a client request body is buffered to a temporary file /tmp/client-body/0000000009,client: 10.10.0.30,server: _,request: "POST /invocations HTTP/1.1",host: "34.90.4.0"
2020/08/26 16:06:45 [error] 86#86: *42282 connect() failed (111: Connection refused) while connecting to upstream,upstream: "http://10.52.3.7:5555/invocations",host: "34.90.4.0"
10.10.0.30 - - [26/Aug/2020:16:06:45 +0000] "POST /invocations HTTP/1.1" 502 157 "-" "python-requests/2.24.0" 86151 0.738 [default-model-inference-service-5555] [] 10.52.3.7:5555,10.52.3.7:5555,10.52.3.7:5555 0,0 0.000,0.001,0.000 502,502,502 0d86e360427c0a81c287da4ff5e907bc

要测试入口和负载均衡器是否在原理上工作,我用想要公开的真实REST API替换了docker映像,该docker image会在端口5050和路径{{1上返回“ hello world” }}。我在上面显示的服务和入口清单中更改了端口和路径(从//invocations),并且在浏览器中访问负载平衡器的ip时可以成功看到“ hello world”。 / p>

有人看到我做错了吗? 非常感谢!

最诚挚的问候,

F

解决方法

您共享的配置看起来不错。群集环境中一定有某种原因导致此现象。查看Pod到Pod的通讯是否正常。在与Nginx入口控制器相同的节点上启动测试容器,并执行从该容器到目标服务的curl。查看是否遇到任何DNS或网络问题。调用服务时尝试更改主机标头,看看它是否对此敏感。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-