简体   繁体   English

无法在同一GKE集群中的2个node.js服务之间进行通信

[英]Unable to communicate between 2 node.js services in same GKE cluster

I have created a GKE cluster and deployed two node.js basic apps in it named nodeservice1 and nodeservice2 where only nodeservice1 is open to world (Allow unauthenticated calls=true) . 我创建了一个GKE集群,并在其中部署了两个名为nodeservice1nodeservice2的 node.js基本应用程序,其中只有nodeservice1向世界开放(允许未经身份验证的调用= true)。

My nodeservice1 is internally calling nodeservice2 via restcall and returning what nodeservice2 returns. 我的nodeservice1正在内部通过restcall调用nodeservice2并返回nodeservice2返回的内容。

I am able to call nodeservice1 via curl command, it works fine. 我可以通过curl命令调用nodeservice1 ,它工作正常。 When I hit endpoint ../restcall (Which actually calls nodeservice2 internally), it doesn't return anything but HTTPS 200 OK . 当我命中终结点../restcall (实际上内部调用nodeservice2 )时,它只返回HTTPS 200 OK

Any help? 有什么帮助吗? TIA TIA

I have tried hitting following URLs from nodeservice1 我尝试从nodeservice1命中以下URL

  1. http://nodeservice1.default.example.com:8080/restcall http://nodeservice1.default.example.com:8080/restcall
  2. http://nodeservice1.default:8080/restcall HTTP://nodeservice1.default:8080 / restcall
  3. http://nodeservice1:8080/restcall HTTP:// nodeservice1:8080 / restcall

Nodeservice1's server.js file: 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's server.js 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');
});

I have faced the same issue few weeks ago. 几周前我也遇到过同样的问题。 I think the problem is your nodeservice1 can't find the nodeservice2 internally,I may suggest try something like nodeservice1.default.svc.cluster.local. 我认为问题是您的nodeservice1无法在内部找到nodeservice2,我建议您尝试使用类似nodeservice1.default.svc.cluster.local的方法。 try the kubectl get svc to list down your services. 尝试使用kubectl get svc列出您的服务。 or if you need to see what happens in your curl command try -v flag with your curl. 或者,如果您需要查看curl命令中发生的情况,请尝试-cur标志与curl配合使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM