Cannot use kompose for converting from docker-compose to kubernetes

8/1/2017

I have project with docker-compose setup ready. Now I want to move to kubernetes. I use Kompose tool for converting from docker-compose to kubernetes.

For example, here is my sample docker-compose.yml file

version: '3'
volumes:
  database_hades_volume:
    external: true
services:
  db:
    image: postgres:latest
    container_name: hades-db
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: hades_dev
      POSTGRES_PASSWORD: 1234
    volumes:
    - database_hades_volume:/var/lib/postgresql/data/
    tty: true
    stdin_open: true
  redis:
    container_name: hades-redis
    image: redis:latest
    ports:
      - "6379:6379"
  app:
    container_name: hades-app
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "4001:4001"
    volumes:
      - ".:/webapp"
    env_file:
      - ./.env.docker_compose-dev
    depends_on:
      - db
      - redis

I have run successfully by using command: docker-compose up. Now, I use kompose for converting to kubernetes by using command:

kompose convert

Then I run by using:

kompose up

Here is command line result information:

INFO We are going to create Kubernetes Deployments, Services and PersistentVolumeClaims for your Dockerized application. If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead.

INFO Deploying application in "default" namespace
INFO Successfully created Service: app
INFO Successfully created Service: db
INFO Successfully created Service: redis
INFO Successfully created Deployment: app
INFO Successfully created PersistentVolumeClaim: app-claim0 of size 100Mi. If your cluster has dynamic storage provisioning, you don't have to do anything. Otherwise you have to create PersistentVolume to make PVC work
INFO Successfully created Deployment: db
INFO Successfully created PersistentVolumeClaim: database-hades-volume of size 100Mi. If your cluster has dynamic storage provisioning, you don't have to do anything. Otherwise you have to create PersistentVolume to make PVC work
INFO Successfully created Deployment: redis

Your application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods,pvc' for details.

But when I try to test by going to localhost:4001 or 10.0.0.180:4001, I see that it's waiting forever.

I don't know if I have setup something wrong or miss some steps. Please help me.

Thanks

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

1 Answer

8/11/2017

Your docker-compose file contains build key which means you have source code/Dockerfile present for app service, As of now,

NAME                        READY     STATUS              RESTARTS   AGE
po/app-2119952459-b4jtb     0/1       ErrImagePull        0          24s

Status is ErrImagePull as cluster is not able to find any image, so along with build key, provide image key as well, for ex.

app:
  container_name: hades-app
  build:
    context: .
    dockerfile: Dockerfile
  image: <username>/<imagename>:<tag>

Because, now kompose has feature of local build and push support, So kompose will build your image, push to dockerhub and then your cluster can pull image from there while deploying.

commands can be like,

kompose up --build=local

I hope this makes sense

-- Suraj Narwade
Source: StackOverflow