<p>I tried to make different pods each of them runs its own container, I tried to follow the same instructions of linking two docker containers:</p>
<pre><code>docker run -d -e POSTGRES_USER=name -e POSTGRES_PASSWORD=pass -e POSTGRES_DB=postgres --name db postgres:10
</code></pre>
<p>The other container:</p>
<pre><code>docker run -p port:port --name image-name --link db:db -t image
</code></pre>
<h2>and the Kubernetes deployments:</h2>
<h2>DB</h2>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: db
  labels:
    app: db
spec:
  replicas: 1
  selector:
    matchLabels:
      app: db
  template:
    metadata:
      labels:
        app: db
    spec:
      containers:
        - name: db
          image: postgres
          ports:
          - containerPort: 5432
          env:
          - name: &quot;POSTGRES_DB&quot;
            value: &quot;postgres&quot;
          - name: &quot;POSTGRES_USERNAME&quot;
            value: &quot;name&quot;
          - name: &quot;POSTGRES_PASSWORD&quot;
            value: &quot;pass&quot;
</code></pre>
<h2>APP</h2>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: APP
  labels:
    app: APP
spec:
  replicas: 1
  selector:
    matchLabels:
      app: APP
  template:
    metadata:
      labels:
        app: APP
    spec:
      containers:
        - name: APP
          image: image
          ports:
          - containerPort: port
</code></pre>
<p>Now the question, do I need to create containers in the same pod and name it in a similar name to the docker command(db=db)?
or do I need to configure the network correctly so containers can find the hostname?</p>

omeraiman
<p>You have to create a service which points to your pod (deployment). Via service, you can manage traffic across deployments.</p>

<p>For more info you can check this document : <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/</a></p>

<p>if you are looking for internal dns communication</p>

<p>please check : <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/</a></p>
