combor / k8s-mongo-labeler-sidecar

Kubernetes MongoDB sidecar that watches replica instances and sets label on primary node.
BSD 3-Clause "New" or "Revised" License
27 stars 18 forks source link

Using this with the official mongodb-replicaset helm chart #1

Closed kwill4026 closed 4 years ago

kwill4026 commented 5 years ago

Hello. So I am interested in using this with the mongodb-replicset helm chart. Following that helm chart, I wanted to find a way to expose the service to external clients such as MongoDB Compass, or simply just connecting to the cluster from an external mongo binary. I created another service-external.yaml file to include ... spec: type: NodePort ports:

Running my helm chart I was able to get the statefulset running with 3 pods to include a primary and two secondaries. Also I was able to expose my service to a node port. Connecting via from within the pods mongo binary or from an external mongo client elsewhere using "mongo -u admin -p password --authenticationDatabase admin node:nodePort" worked fine with no issues. However at times it would connect to secondaries and not always the primary. I attempted to do the same using the mongo URI to include all 3 pods in the string. This worked connecting to the primary at all times within the mongo binary/client in the pod but doing the same externally didn't thus changing my connection to the Kubernetes internal hostname and failing.

I am not familiar too much with go so I was unsure as to exactly how to get your side car mongo labeler working with this helm chart. Is there anything I need to change or add to my helm chart.

combor commented 5 years ago

Hi @kwill4026 . Sorry I missed your issue, it seems that github notifications do not work for me. I recon you need to modify you helm chart to include something like this in the stateful set manifest:

        - name: mongo-labeler-sidecar
          image: combor/k8s-mongo-labeler-sidecar:latest
          imagePullPolicy: IfNotPresent
          env:
            - name: LABEL_SELECTOR
              value: "role=mongo,environment=prod"
            - name: NAMESPACE
              value: "prod"

This works for me

combor commented 4 years ago

I'm gonna close this now.