<p>For my research project, I need to deploy Graylog in our Kubernetes infrastructure. Graylog uses MongoDB which is deployed on the same cluster.</p>
<pre><code>kubectl describe svc -n mongodb

Name:              mongodb
Namespace:         mongodb
Labels:            app=mongodb
Annotations:       Selector:  app=mongodb
Type:              ClusterIP
IP:                10.109.195.209
Port:              27017  27017/TCP
TargetPort:        27017/TCP
Endpoints:         10.244.2.21:27017
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>
<p>I use the deployment script bellow to deploy Graylog:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: graylog3
spec:
  type: NodePort
  selector:
    app: graylog-deploy
  ports:
  - name: &quot;9000&quot;
    port: 9000
    targetPort: 9000
    nodePort: 30003
  - name: &quot;12201&quot;
    port: 12201
    targetPort: 12201
    nodePort: 30004
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: graylog-deploy
  labels:
    app: graylog-deploy
spec:
  replicas: 1
  selector:
      matchLabels:
        name: graylog-deploy

  template:
    metadata:
      labels:
        name: graylog-deploy
        app: graylog-deploy
    spec:
      containers:
      - name: graylog3
        image: graylog/graylog:3.0
        env:
        - name: GRAYLOG_PASSWORD_SECRET
          value: g0ABP9MJnWCjWtBX9JHFgjKAmD3wGXP3E0JQNOKlquDHnCn5689QAF8rRL66HacXLPA6fvwMY8BZoVVw0JqHnSAZorDDOdCk
        - name: GRAYLOG_ROOT_PASSWORD_SHA2
          value: 8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
        - name: GRAYLOG_HTTP_EXTERNAL_URI
          value: http://Master_IP:30003/ 
        - name: GRAYLOG_ELASTICSEARCH_HOSTS
          value: http://elasticsearch:9200
        - name: GRAYLOG_MONGODB_URI
          value: mongodb://mongodb:27017/graylog
        ports:
        - containerPort: 9000
        - containerPort: 12201
</code></pre>
<p>Graylog is throwing an exception:</p>
<blockquote>
<p>Caused by: java.net.UnknownHostException: mongodb</p>
</blockquote>
<p>But when deploying it using the MongoDB IP, it runs successfully.</p>
<p>I am new to Kubernetes and don't know what I am doing wrong here.</p>
<p>Thanks.</p>

Alexa
<p>Since your mongodb is running in a different namespace called mongodb , you need to provide the FQDN for the service in that namespace. Your graylog is in default namespace.
So to access the mongodb service in mongodb namespace change your yaml as below</p>
<pre><code>- name: GRAYLOG_MONGODB_URI
  value: mongodb://mongodb.mongodb:27017/graylog
</code></pre>
<p><a href="https://stackoverflow.com/questions/56334974/connect-to-kubernetes-mongo-db-in-different-namespace">Here</a> is link that might provide more insights.</p>
