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

<p>First, check that the service is created</p>

<p><code>kubectl describe svc mongo</code></p>

<p>You should see it show that it is both created and routing to your pod's IP.  If you're wondering what your pod's IP is you can check it out via</p>

<p><code>kubectl get po | grep mongo</code></p>

<p>Which should return something like: <code>mongo-deployment-&lt;guid&gt;-&lt;guid&gt;</code>, then do</p>

<p><code>kubectl describe po mongo-deployment-&lt;guid&gt;-&lt;guid&gt;</code></p>

<p>You should make sure the pod is started correctly and says <code>Running</code> not something like <code>ImagePullBackoff</code>.  It looks like you're mounting a volume from a <code>gcePersistentDisk</code>.  If you're seeing your pod just hanging out in the <code>ContainerCreating</code> state it's very likely you're not mounting the disk correctly.  Make sure you <a href="http://kubernetes.io/docs/user-guide/volumes/#creating-a-pd" rel="noreferrer">create the disk</a> before you try and <a href="http://kubernetes.io/docs/user-guide/volumes/#example-pod-2" rel="noreferrer">mount it as a volume</a>.</p>

<p>If it looks like your service is routing correctly, then you can check the logs of your pod to make sure it started mongo correctly:</p>

<p><code>kubectl logs mongo-deployment-&lt;guid&gt;-&lt;guid&gt;</code></p>

<p>If it looks like the pod and logs are correct, you can exec into the pod and make sure mongo is actually starting and working:
<code>kubectl exec -it mongo-deployment-&lt;guid&gt;-&lt;guid&gt; sh</code></p>

<p>Which should get you into the container (Pod) and then you can try <a href="https://stackoverflow.com/a/5521155/316857">something like this</a> to see if your DB is running.</p>
