首页 > 解决方案 > 无法在启用了 Istio 的 GKE 集群中的 2 个节点、js 应用程序之间进行通信

问题描述

我创建了一个 GKE 集群并在其中部署了两个名为nodeservice1nodeservice2的 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。

  1. http://nodeservice2.istio-system:8080/restcall
  2. http://nodeservice2:8080/restcall

/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');
});

标签: node.jsgoogle-cloud-platformgoogle-kubernetes-engineistio

解决方案


几周前我也遇到过同样的问题。我认为问题是您的 nodeservice1 在内部找不到 nodeservice2,我可能会建议尝试类似 nodeservice1.default.svc.cluster.local 的东西。尝试使用 kubectl get svc 列出您的服务。或者,如果您需要查看 curl 命令中发生的情况,请尝试使用 curl 使用 -v 标志。


推荐阅读