title: Cannot connect to a mongodb service in a Kubernetes cluster
body: <p>I have a Kubernetes cluster on Google Cloud, I have a database service, which is running in front of a mongodb deployment. I also have a series of microservices, which are attempting to connect to that datastore. </p>
  
  <p>However, they can't seem to find the host. </p>
  
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
   labels:
     name: mongo
   name: mongo
  spec:
   ports:
   - port: 27017
     targetPort: 27017
   selector:
     name: mongo
  </code></pre>
  
  <p>Here's my mongo deployment... </p>
  
  <pre><code>apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: mongo-deployment
  spec:
    replicas: 1
    template:
      metadata:
        labels:
          name: mongo
      spec:
        containers:
        - image: mongo:latest
          name: mongo
          ports:
          - name: mongo
            containerPort: 27017
            hostPort: 27017
          volumeMounts:
            - name: mongo-persistent-storage
              mountPath: /data/db
        volumes:
          - name: mongo-persistent-storage
            gcePersistentDisk:
              pdName: mongo-disk
              fsType: ext4
  </code></pre>
  
  <p>And an example of one of my services... </p>
  
  <pre><code>apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: bandzest-artists
  spec:
    replicas: 1
    template:
      metadata:
        labels:
          name: bandzest-artists
      spec:
        containers:
        - name: artists-container
          image: gcr.io/&lt;omitted&gt;/artists:41040e8
          ports: 
          - containerPort: 7000
          imagePullPolicy: Always
          env:
          - name: DB_HOST
            value: mongo
          - name: AWS_BUCKET_NAME
            value: &lt;omitted&gt;
          - name: AWS_ACCESS_KEY_ID
            value: &lt;omitted&gt;
          - name: AWS_SECRET_KEY
            value: &lt;omitted&gt; 
  </code></pre>