how to deploy app with docker compose to kubernetes

2/27/2019

I'm new to docker and kubernetes.I have docker-compose.yml as

version: '2'
services:
  db:
    build:
      context: ./db
      dockerfile: Dockerfile
    ports:
      - "3306:3306"
    networks:
      docker-network:
        ipv4_address: 172.18.0.2
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: db
      MYSQL_USER: user
      MYSQL_PASSWORD: mypassword

  createlinuxuser:
    build:
      context: ./createlinuxuser
      dockerfile: Dockerfile
    networks:
      docker-network:
        ipv4_address: 172.18.0.3
    depends_on:
      - db
    tty: true
    restart: always

networks:
  docker-network:
    driver: bridge
    ipam:
     config:
       - subnet: 172.18.0.0/16  
         gateway: 172.18.0.1 

I want to deploy this multi container docker app with bridge network between containers on kubernetes. I also want to have Ip to both containers on kubernetes so that they can talk to each other,is this possible? What is the best practice to do this?

-- stacylouis
containers
docker
kubernetes

2 Answers

3/7/2019

Another feature that you might need to take a look at, is to deploy to kuberentes using docker cli itself as explained in docker stack deploy

  • Client and daemon API must both be at least 1.25 to use this command

  • The deploy command supports compose file version 3.0 and above. So you might need to update the docker-compose.yml to v3

docker stack deploy --compose-file /path/to/docker-compose.yml mystack

Other options can be specified like: --namespace, --kubeconfig

Also you can check out Helm which is a package manager for kubernetes where you need to write a helm chart in order to deploy it on kubernetes cluster

-- Mostafa Hussein
Source: StackOverflow

3/7/2019

Just as David Maze said, there might be some issues with what you want to achieve. Definitely you won't be able to just use this file straight away. You can use Kompose to go from Docker Compose to Kubernetes or kompose convert.

Kompose supports conversion of V1, V2, and V3 Docker Compose files into Kubernetes and OpenShift objects. But as mentioned it will probably require some adjustments.

As for your networking. Do you want multiple containers in a Pod or you want to deploy it all as separate pods? In this case read the documentation or some articles about Kubernetes Networking.

In terms of Docker constructs, a Pod is modelled as a group of Docker containers that share a network namespace. Containers within a Pod all have the same IP address and port space assigned through the network namespace assigned to the Pod, and can find each other via localhost since they reside in the same namespace.

source

-- aurelius
Source: StackOverflow