我正在尝试在Kubernetes中运行一个有状态的Mongo,它可以在Istio之外使用这些配置。
mongodb: {
uri: "mongodb://mongo-0.mongo,mongo-1.mongo,mongo-2.mongo",
dbName: "app"
}
但是当我在Istio中运行节点应用程序时,它失去了连接到mongo的能力。有没有我缺少的东西,或者是因为我不能在Istio中使用有状态集?
下面有状态的mongo配置。
apiVersion: v1
kind: Service
metadata:
labels:
service: mongo
name: mongo
spec:
ports:
- name: tcp
port: 27017
targetPort: 27017
clusterIP: None
selector:
service: mongo
role: mongo
***********
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: mongo
spec:
serviceName: "mongo"
replicas: 3
template:
metadata:
labels:
role: mongo
environment: test
service: mongo
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mongo
image: mongo:3.4.6
resources:
requests:
cpu: "10m"
command:
- mongod
- "--replSet"
- rs0
- "--smallfiles"
- "--noprealloc"
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
- name: mongo-sidecar
image: cvallance/mongo-k8s-sidecar
resources:
requests:
cpu: "10m"
env:
- name: MONGO_SIDECAR_POD_LABELS
value: "role=mongo,environment=test"
我收到的错误是
[2017-07-25 12:01:11] ERROR Mongoose MonboDB connection error: {
"message": "write EPIPE",
"name": "MongoError",
"stack": "Error: write EPIPE\n at exports._errnoException (util.js:1024:11)\n at WriteWrap.afterWrite [as oncomplete] (net.js:851:14)"
}
[2017-07-25 12:01:11] ERROR ... retrying createConnection in 5 seconds...
[2017-07-25 12:01:16] ERROR Mongoose MonboDB connection error: {
"message": "read ECONNRESET",
"name": "MongoError",
"stack": "Error: read ECONNRESET\n at exports._errnoException (util.js:1024:11)\n at TCP.onread (net.js:610:25)"
}
答案 0 :(得分:0)
最近添加了StatefulSet支持,但它尚未发布。
答案 1 :(得分:0)
对于那些在istio中通过手动注入收到此类错误的人:
在将代理注入到部署中时,在配置istio-proxy时会丢弃网络:
kubectl apply -f kubernetes-configs/
istioctl kube-inject -f kubernetes-configs/deployment.yml | kubectl -n foo apply -f -
到那时,您将收到:
Error: write EPIPE
我通过在初始化之前添加暂停来解决了这个问题,例如:How Can I Wait In Node.js (Javascript), l need to pause for a period of time
更新
这是另一种方式。只需让nodejs应用重新启动即可。通过在连接不成功的任何地方调用process.exit(137)
, Docker容器将被杀死并重新启动。到那时,istio-proxy将完成网络配置,您的应用程序将成功连接到DB。