gpt4 book ai didi

node.js - Minikube 与 Istio 服务不可用(http 状态 503)Node.js 连接到 Etcd

转载 作者:太空宇宙 更新时间:2023-11-04 00:21:26 25 4
gpt4 key购买 nike

我一直在开发一个简单的 Node.js 应用程序,该应用程序使用 Istio 从 etcd 设置和获取 key ,以将两个服务连接在一起。我尝试了一些变体,但仍然看到返回相同的错误。

nodeAppTesting failed(etcd-operator) ->{"errors":[{"server":"http://etcd-operator:2379","httperror":null,"httpstatus":503,"httpbody":"upstream connect error or disconnect/reset before headers","response":{"statusCode":503,"body":"upstream connect error or disconnect/reset before 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","path":"/v2/keys/testKey","href":"http://etcd-operator:2379/v2/keys/testKey"},"method":"GET","headers":{"accept":"application/json"}}},"timestamp":"2017-06-08T17:17:04.544Z"}],"retries":0}

查看代理日志,我可以看到客户端和服务器代理参与了通信(我认为这在服务器 header 中看到 envoy 时得到了验证)。

附加Node.js 应用程序和deployment.yaml。server.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")

deployment.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

---

最佳答案

我能够解决此处报告的问题。我将在本周的某个时候发布一个演示流程的食谱。现在,我们可以认为这已结束。将来,我将转向论坛或发布有关问题的帖子。请留意这篇文章(我将在可用时使用链接更新这篇文章)。感谢您的帮助、指导和建议。

主要问题是引用 etcd 服务的一致性,引用我的 Node 应用程序作为部署、服务和入口的一致性,最后是公开 NodePort。

更新

Published a article demonstrating the working flow.

关于node.js - Minikube 与 Istio 服务不可用(http 状态 503)Node.js 连接到 Etcd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44442632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com