Kubernetes: mapping between Deployments Services Pods to docker concept

7/15/2017

I'm learning Kubernetes. I'm trying to mapping equivalent concept from Kubernetes to Docker. For example: I have a following docker-compose.yml

db:
  container_name: db
  image: postgres:latest
  ports:
    - "5432:5432"
  environment:
    POSTGRES_PASSWORD: 1234

app:
  container_name: app
  build: .
  dockerfile: Dockerfile
  ports:
    - "3000:3000"
  volumes:
    - ".:/webapp"
  env_file:
    - ./.env.docker_compose
  links:
    - db

This docker-compose.yml has two components: db and app. There are 2 ways for understanding. I don't know which one is true and which one is wrong.

  • First understanding: each components are inside in each pod. This means db in one pod, and app in one pod.
  • Second understanding: both db and app are all in one Pod.

Please tell me which one is true. The same question for Deployment and Service. How can I map to docker concept.

Thanks

-- Trần Kim Dự
docker
docker-compose
kubernetes

1 Answer

7/15/2017

A pod being a group of one or more container, your docker-compose would by default mimick one pod. (so your second interpretation)

But with docker swarm mode, you can make sure those two container are in their own "pod" (as a group of one container) with constraints.
With dockerfile v3, you have for instance placement (also seen in docker service create)

version: '3'
services:
  db:
    image: postgres
    deploy:
      placement:
        constraints:
          - node.role == manager
          - engine.labels.operatingsystem == ubuntu 14.04
-- VonC
Source: StackOverflow