<p>This is my appsettings.json </p>

<pre><code>{
  "ConnectionStrings": {
    "PackingService": "mongodb://127.0.0.1:27017/test"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}
</code></pre>

<p>This is my Deployment for app </p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: test
  name: test
spec:
  selector:
    matchLabels:
      app: test
  strategy: {}
  template:
    metadata:
      labels:
        io.kompose.network/dbnet: "true"
        app: test
    spec:
      containers:
      - env:
        - name: ConnectionStrings
          value: mongodb://localhost/test
        - name: MONGO_PORT
          valueFrom:
            configMapKeyRef:
              key: MONGO_PORT
              name: env
        - name: NODE_ENV
          value: development
        image: mlrd/smartboxes
        imagePullPolicy: ""
        name: test-api
        ports:
        - containerPort: 80
        resources: {}
      restartPolicy: Always
      serviceAccountName: ""
      volumes: null
status: {}
</code></pre>

<p>This is my Service for Mongodb</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mongodb
  labels:
    app: mongodb
spec:
  ports:
    - port: 27017
  selector:
    app: mongodb
</code></pre>

<p>This doesn't work throws an error time out when I want to connect to database, what is proper way to sent connection string to application from .yaml file? Should I set aspnetcore env variable also? Should I change something in .json config file? Sorry for lack of knowledge</p>

Biljana Glumac
<p>Since mongodb is deployed as a separate pod and exposed by a service you can't use <code>localhost</code> or <code>127.0.0.1</code> If you have created the mongodb service in the same namespace as the app then you should use  <code>mongodb.svc.cluster.local</code>. If mongodb service is in different namespace then use <code>mongodb.namespacename.svc.cluster.local</code></p>
