我一直在开发一个简单的 Node.js 应用程序,该应用程序使用 Istio 从 etcd 中设置和获取密钥以将两个服务连接在一起。我尝试了一些变体,但仍然看到返回相同的错误。
nodeAppTesting failed(etcd-operator) ->{"errors":[{"server":" http://etcd-operator:2379 ","httperror":null,"httpstatus":503,"httpbody":"upstream连接错误或在 headers 之前断开/重置","response":{"statusCode":503,"body":"上游连接错误或在 headers 之前断开/重置","headers":{"content-length":"57 ","content-type":"text/plain","date":"Thu, 08 Jun 2017 17:17:04 GMT","server":"envoy","x-envoy-upstream-service-time ":"5"},"request":{"uri":{"protocol":"http:","slashes":true,"auth":null,"host":"etcd-operator:2379","port":"2379","hostname":"etcd-operator","hash":null,"search":null,"query":null,"pathname":"/v2/keys/testKey ","路径":"/v2/keys/testKey","href":" http://etcd-operator:2379/v2/keys/testKey"},"method":"GET","headers":{"accept":"application/json"}}},"timestamp":"2017-06-08T17:17:04.544Z"}],"重试“:0}
查看代理日志,我可以看到客户端和服务器代理参与了通信(我认为在服务器标头中看到 envoy 时验证了这一点)。
附加 Node.js 应用程序和 deployment.yaml。 服务器.js
var http = require('http');
var Etcd = require('node-etcd');
var fs = require('fs');
var httpClient = require('request');
var handleRequest = function(request, response) {
var scheme = "http";
var ipAddress = "etcd-operator"
var port = "2379";
var connectionAddress = scheme +"://" + ipAddress +":" + port;
console.log('Received request for URL: ' + request.url + " connecting to " + connectionAddress);
var etcd = new Etcd([connectionAddress] /*, options */);
etcd.set("testKey" , "foo");
etcd.get("testKey", function(err, res){
if(!err){
response.writeHead(200);
response.write("nodeAppTesting("+ ipAddress+") ->"+ JSON.stringify(res) ) ;
response.end();
}else{
response.writeHead(500);
response.write("nodeAppTesting failed("+ ipAddress+") ->"+ JSON.stringify(err) ) ;
console.log("Encountered error during runtime", JSON.stringify(err));
response.end();
}
});
}
var www = http.createServer(handleRequest);
www.listen(8080);
console.log("App up and running on port 8080")
部署.yaml
apiVersion: v1
kind: Service
metadata:
name: etcd-node
labels:
app: etcd-node
spec:
ports:
- port: 8080
name: http
selector:
app: etcd-node
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: etcd-node-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: etcd-node
spec:
containers:
- name: etcd-node
image: todkap/etcd-node:v1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
---
##################################################################################################
# etcd service
##################################################################################################
apiVersion: v1
kind: Service
metadata:
name: etcd-operator
labels:
app: etcd-operator
spec:
ports:
- port: 2379
targetPort: 2379
name: http
selector:
app: etcd-operator
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: etcd-operator
spec:
replicas: 1
template:
metadata:
labels:
name: etcd-operator
app: etcd-operator
version: v1
spec:
containers:
- name: etcd-operator
image: quay.io/coreos/etcd-operator:v0.2.6
imagePullPolicy: IfNotPresent
env:
- name: MY_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
ports:
- containerPort: 2379
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: gateway2
annotations:
kubernetes.io/ingress.class: "istio"
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: etcd-node
servicePort: 8080
- http:
paths:
- path: /
backend:
serviceName: etcd-operator
servicePort: 2379
- path: /v2/keys/*
backend:
serviceName: etcd-operator
servicePort: 2379
---