<p>I'm well versed in Docker, but must be doing something wrong here with K8. I'm running <code>skaffold</code> with <code>minikube</code> and trying to get DNS between containers working. Here's my deployment:</p>

<pre><code>kind: Deployment
apiVersion: apps/v1
metadata:
  name: my-api
  labels:
    app: my-api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-api
  template:
    metadata:
      name: my-api
      labels:
        app: my-api
    spec:
      containers:
      - name: my-api-postgres
        image: postgres:11.2-alpine
        env:
        - name: POSTGRES_USER
          value: "my-api"
        - name: POSTGRES_DB
          value: "my-api"
        - name: POSTGRES_PASSWORD
          value: "my-pass"
        ports:
        - containerPort: 5432
      - name: my-api-redis
        image: redis:5.0.4-alpine
        command: ["redis-server"]
        args: ["--appendonly", "yes"]
        ports:
        - containerPort: 6379
      - name: my-api-node
        image: my-api-node
        command: ["npm"]
        args: ["run", "start-docker-dev"]
        ports:
        - containerPort: 3000
</code></pre>

<p>However, in this scenario <code>my-api-node</code> can't contact <code>my-api-postgres</code> via the DNS hostname <code>my-api-postgres</code>. Any idea what I'm doing wrong?</p>

Fmstrat
<p>You have defined all 3 containers as part of the same pod. Pods have a common network namespace so in your current setup (which is not correct, more on that in a second), you could talk to the other containers using <code>localhost:&lt;port&gt;</code>. </p>

<p>The 'correct' way of doing this would be to create a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">deployment</a> for each application, and front those deployments with <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">services</a>. </p>

<p>Your example would roughly become (untested):</p>

<pre><code>kind: Deployment
apiVersion: apps/v1
metadata:
  name: my-api-node
  namespace: my-api
  labels:
    app: my-api-node
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-api-node
  template:
    metadata:
      name: my-api-node
      labels:
        app: my-api-node
    spec:
      containers:
      - name: my-api-node
        image: my-api-node
        command: ["npm"]
        args: ["run", "start-docker-dev"]
        ports:
        - containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
  namespace: my-api
  name: my-api-node
spec:
  selector:
    app: my-api-node
  ports:
  - protocol: TCP
    port: 3000
    targetPort: 3000
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: my-api-redis
  namespace: my-api
  labels:
    app: my-api-redis
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-api-redis
  template:
    metadata:
      name: my-api-redis
      labels:
        app: my-api-redis
    spec:
      containers:
      - name: my-api-redis
        image: redis:5.0.4-alpine
        command: ["redis-server"]
        args: ["--appendonly", "yes"]
        ports:
        - containerPort: 6379
---
apiVersion: v1
kind: Service
metadata:
  namespace: my-api
  name: my-api-redis
spec:
  selector:
    app: my-api-redis
  ports:
  - protocol: TCP
    port: 6379
    targetPort: 6379
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: my-api-postgres
  namespace: my-api
  labels:
    app: my-api-postgres
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-api-postgres
  template:
    metadata:
      name: my-api-postgres
      labels:
        app: my-api-postgres
    spec:
      containers:
      - name: my-api-postgres
        image: postgres:11.2-alpine
        env:
        - name: POSTGRES_USER
          value: "my-api"
        - name: POSTGRES_DB
          value: "my-api"
        - name: POSTGRES_PASSWORD
          value: "my-pass"
        ports:
        - containerPort: 5432
---
apiVersion: v1
kind: Service
metadata:
  namespace: my-api
  name: my-api-postgres
spec:
  selector:
    app: my-api-postgres
  ports:
  - protocol: TCP
    port: 5432
    targetPort: 5432
</code></pre>

<p>DNS records get registered for <em>services</em> so you are connecting to those and being forwarded to the pods behind it (simplified). If you need to get to your node app from the outside world, that's a whole additional deal, and you should look at <a href="https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer" rel="nofollow noreferrer"><code>LoadBalancer</code></a> type services, or <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Ingress</a>.</p>
