node.js - 无法在启用了 Istio 的 GKE 集群中的 2 个节点、js 应用程序之间进行通信
问题描述
我创建了一个 GKE 集群并在其中部署了两个名为nodeservice1和nodeservice2的 node.js 基本应用程序,其中只有nodeservice1对世界开放 (Allow unauthenticated calls=true) 。
我的nodeservice1通过 restcall在内部调用nodeservice2并返回nodeservice2返回的内容。
我可以通过 curl 命令调用nodeservice1 ,它工作正常。当我点击端点../restcall
(实际上在内部调用nodeservice2)时,它只返回HTTPS 200 OK
.
注意:这两个应用程序都在“云运行”上。以上设置
有什么帮助吗?TIA
我尝试从nodeservice1中点击以下 URL 。也尝试了 curl 命令: curl -v -H "Host: nodeservice1.istio-system.example.com" 34.80.18.249/restcall 其中 34.80.18.249 是我的 istio 入口负载均衡器 IP。
/restcall 在内部调用 nodeservice2
当我检查正在运行的服务时,我的 nodeservice1 和 nodeservice2 的 type=ExternalName。但是我已经暴露了 nodeservice1=Loadbalancer 和 Nodeservice2=ClusterIP。我错过了什么吗?
Nodeservice1 的 server.js 文件:
var express = require("express");
var http = require('http');
var app = express();
app.get('/',function(req, res, next){
res.send('Hurrah !!! nodeservice1 is up and running !!!');
});
app.get('/restcall',function(req, res, next){
var data = '';
console.log('inside /restcall in nodeservice1');
http.get('http://nodeservice1.default.example.com:8080/restcall',(resp) =>{
console.log('inside response');
resp.on('data', function (chunk) {
data += chunk;
console.log('inside end restcall');
});
resp.on('end', () => {
res.send(data);
console.log('inside end restcall');
console.log(data);
})
})
})
app.listen('8080',function(){
console.log('Node service 2 server listening on port 8080');
});
Nodeservice2 的 server.js
var express = require("express");
var http = require('http');
var app = express();
app.get('/',function(req, res){
res.send('Hurrah !!! nodeservice2 is up and running !!!');
});
app.get('/restcall',function(req, res, next){
console.log('inside /restcall in nodeservice2');
res.send('restcall api successfull from nodeservice2 !!!');
});
app.listen('8080',function(){
console.log('Node service 2 server listening on port 8080');
});
解决方案
几周前我也遇到过同样的问题。我认为问题是您的 nodeservice1 在内部找不到 nodeservice2,我可能会建议尝试类似 nodeservice1.default.svc.cluster.local 的东西。尝试使用 kubectl get svc 列出您的服务。或者,如果您需要查看 curl 命令中发生的情况,请尝试使用 curl 使用 -v 标志。
推荐阅读
- mysql - MySQL“where”条件没有返回正确的数据
- python - 理解 for 循环中的 range()
- php - PHP rename() 函数:文字字符串与变量
- android - Android - 获取不同的 UTC 时间
- asp.net - 如何从 SharePoint 应用程序和 WPF 配置和调用非匿名 WCF 服务?
- rx-java - RxJava:如果源太慢,则插入额外的发射
- c# - 我们可以将 HTML 存储在附件中吗?
- jquery - 使用 val() 验证文本输入
- java - 为什么 Apache POI 会读取已手动擦除的行?
- javascript - 如何在javascript中删除日期中年份的前两位数字?