You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kubernetes中通过Service实现Pod间通信时URI无效报错求助

问题排查与解决方案

1. 修复HttpClient请求URI错误

你遇到的An invalid request URI was provided错误,核心原因是请求的URI存在格式或完整性问题,结合你的Service配置,需要做以下调整:

  • 补全服务端口:你的cepserviceone Service暴露的端口是8080,但请求URL里未包含这个端口,正确的URI应该是:
    HttpClient req = new HttpClient();
    var content = await req.GetAsync("http://cepserviceone.cep-dev.svc.cluster.local:8080/api/values");
    string response = await content.Content.ReadAsStringAsync();
    return response;
    
  • 确认协议类型:如果你的目标服务(cepserviceone)没有配置HTTPS证书,不要用https://,改用http://,否则后续还会触发证书验证错误。

2. 检查Service配置的正确性

你的第二个Service配置存在潜在问题,可能导致服务无法关联到后端Pod:

  • Selector标签不匹配:第二个Service的spec.selector.app设置为cepservice,但Service自身的metadata.labels.app是cepserviceone。请确认后端Pod的app标签是否为cepservice,如果Pod的app标签是cepserviceone,需要将Selector修改为:
    selector:
      app: cepserviceone
      instance: app
    
  • TargetPort验证:确保targetPort: 80和后端Pod容器实际监听的端口一致,如果容器是在其他端口(比如5000)提供服务,需要同步修改这个值。

3. 验证内部网络连通性

在发起请求的Pod内部,用curl命令测试服务可达性,排除代码之外的网络问题:

curl http://cepserviceone.cep-dev.svc.cluster.local:8080/api/values

如果curl能正常返回响应,说明网络和Service配置没问题,问题仅在代码层面;如果curl失败,需要进一步检查Service的Selector是否匹配Pod标签、Pod是否正常运行。

内容的提问来源于stack exchange,提问作者Niranjan godbole

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 15:15:59