ElasticsearchJS在Kubernetes Google Cloud上超时?

时间:2018-05-06 07:45:27

标签: node.js elasticsearch google-kubernetes-engine

我在GKE的pod上运行了一个NodeJS应用程序,由于某种原因,我的应用程序在对Elasticsearch(与Kubernetes集群位于同一区域的VM)的所有请求中超时。奇怪的是,如果我使用我的应用程序使用的相同设置创建一个简单的客户端(直接在容器中,通过节点repl),所有请求都将完成。

我注意到我的应用程序能够请求Elasticsearch并在启动时收到响应(当没有与应用程序的HTTP连接时)。它是一个简单的REST端点。这是容器日志:

[2018-05-06T07:46:14.906Z] TRACE (identity/26 on identity-deployment-54d5c7ccb9-hj2k6): REST request
req: {
  "headers": {
    "host": "research.evosec.ws",
    "connection": "close",
    "x-real-ip": "201.6.141.44",
    "x-forwarded-for": "201.6.141.44",
    "x-forwarded-host": "research.evosec.ws",
    "x-forwarded-port": "443",
    "x-forwarded-proto": "https",
    "x-original-uri": "/identity/user",
    "x-scheme": "https",
    "x-original-forwarded-for": "201.6.141.44, 35.201.82.80",
    "content-type": "application/json",
    "cache-control": "no-cache",
    "postman-token": "5646d274-4ed3-44d8-952a-abab50ff7f52",
    "user-agent": "PostmanRuntime/7.1.1",
    "accept": "*/*",
    "accept-encoding": "gzip, deflate",
    "x-cloud-trace-context": "52330745e4ee03559f557b56026f1808/1724170532745914334",
    "via": "1.1 google"
  },
  "method": "GET",
  "remoteAddress": "201.6.141.44",
  "url": "/user"
}
[2018-05-06T07:46:14.908Z] DEBUG (elasticsearch/26 on identity-deployment-54d5c7ccb9-hj2k6): starting request {"method":"POST","path":"/identity_user/user/_search","body":{"query":{"bool":{"filter":{"bool":{"must":[{"term":{"trash":false}},{"term":{"document_type.keyword":"user"}}]}}}}},"query":{"from":0,"size":10,"_source_include":"nickname,username,email,is_email_validated,email_validation_date,system_ownership,user_groups,roles,trash,created_at,last_update"}}
[2018-05-06T07:46:44.910Z] TRACE (identity/26 on identity-deployment-54d5c7ccb9-hj2k6): Return response error
error: {
  "message": "Request Timeout after 30000ms",
  "stack":
      Error: Request Timeout after 30000ms
          at /usr/src/app/node_modules/elasticsearch/src/lib/transport.js:354:15
          at Timeout.<anonymous> (/usr/src/app/node_modules/elasticsearch/src/lib/transport.js:383:7)
          at ontimeout (timers.js:482:11)
          at tryOnTimeout (timers.js:317:5)
          at Timer.listOnTimeout (timers.js:277:5)
}
[2018-05-06T07:46:44.911Z] ERROR (identity/26 on identity-deployment-54d5c7ccb9-hj2k6): Server error
req: {
  "headers": {
    "host": "research.evosec.ws",
    "connection": "close",
    "x-real-ip": "201.6.141.44",
    "x-forwarded-for": "201.6.141.44",
    "x-forwarded-host": "research.evosec.ws",
    "x-forwarded-port": "443",
    "x-forwarded-proto": "https",
    "x-original-uri": "/identity/user",
    "x-scheme": "https",
    "x-original-forwarded-for": "201.6.141.44, 35.201.82.80",
    "content-type": "application/json",
    "cache-control": "no-cache",
    "postman-token": "5646d274-4ed3-44d8-952a-abab50ff7f52",
    "user-agent": "PostmanRuntime/7.1.1",
    "accept": "*/*",
    "accept-encoding": "gzip, deflate",
    "x-cloud-trace-context": "52330745e4ee03559f557b56026f1808/1724170532745914334",
    "via": "1.1 google"
  },
  "method": "GET",
  "remoteAddress": "201.6.141.44",
  "url": "/user"
}
resHeaders: {
  "content-type": "application/json",
  "content-length": 77
}
resBody: {
  "errors": [
    {
      "displayName": "RequestTimeout",
      "message": "Request Timeout after 30000ms",
      "stack": "Error: Request Timeout after 30000ms\n    at /usr/src/app/node_modules/elasticsearch/src/lib/transport.js:354:15\n    at Timeout.<anonymous> (/usr/src/app/node_modules/elasticsearch/src/lib/transport.js:383:7)\n    at ontimeout (timers.js:482:11)\n    at tryOnTimeout (timers.js:317:5)\n    at Timer.listOnTimeout (timers.js:277:5)"
    }
  ]
}
[2018-05-06T07:46:44.912Z] TRACE (elasticsearch/26 on identity-deployment-54d5c7ccb9-hj2k6): 
method: "POST"
requestUrl: {
  "method": "POST",
  "protocol": "http:",
  "hostname": "elasticsearch-0",
  "port": 9200,
  "path": "/identity_user/user/_search?from=0&size=10&_source_include=nickname%2Cusername%2Cemail%2Cis_email_validated%2Cemail_validation_date%2Csystem_ownership%2Cuser_groups%2Croles%2Ctrash%2Ccreated_at%2Clast_update",
  "headers": {
    "content-type": "application/json"
  }
}
body: "{\"query\":{\"bool\":{\"filter\":{\"bool\":{\"must\":[{\"term\":{\"trash\":false}},{\"term\":{\"document_type.keyword\":\"user\"}}]}}}}}"
responseStatus: 0

任何人都知道发生了什么事?

修改

更多信息:

我在使用netstat的请求期间监视了我的应用程序的连接。与Kafka的连接没问题,请求连接(端口8090)没问题,但是与Elasticsearch的连接甚至没有出现!

Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         
State       PID/Program name
tcp        0      0 10.0.2.14:60250         10.150.0.8:9092         
ESTABLISHED 25/node
tcp        0      0 10.0.2.14:44686         10.150.0.8:9092         
ESTABLISHED 26/node
tcp        0      0 10.0.2.14:60260         10.150.0.8:9092         
ESTABLISHED 25/node
tcp        0      0 10.0.2.14:8090          10.0.1.12:53234         
ESTABLISHED 26/node
tcp        0      0 10.0.2.14:60256         10.150.0.8:9092         
ESTABLISHED 26/node

1 个答案:

答案 0 :(得分:0)

您似乎通过外部IP连接?如果是这样,

  1. 检查防火墙规则中是否已打开端口9200。
  2. 通过内部IP连接到您的应用程序(我知道它们是 在同一个网络中。)。