0

我正在尝试在 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)"
}
4

2 回答 2

0

最近添加了 StatefulSet 支持,但尚未发布。

https://github.com/istio/pilot/pull/896

于 2017-07-25T20:24:39.857 回答
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

我通过在初始化之前添加暂停解决了这个问题:我如何在 Node.js (Javascript) 中等待,我需要暂停一段时间


更新

这是另一种方式。只需让 nodejs 应用重新启动即可。process.exit(137)通过在任何连接不成功的地方调用, Docker 容器将被杀死并重新启动。届时,istio-proxy 将完成网络配置,您的应用将成功连接到 DB。

于 2018-12-14T21:34:33.987 回答