2

i am trying to migrate a docrized project to kubernetes, i have used Kompose to convert the project

kompose --file docker-compose.yml convert,

when i run kompose up after migrating the files i get this error

$ kompose up WARN Unsupported env_file key - ignoring
FATA Error while deploying application: k.Transform failed: image key required within build parameters in order to build and push service 'drkiq'

.env file:

SECRET_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx WORKER_PROCESSES=1 LISTEN_ON=0.0.0.0:8000 DATABASE_URL=postgresql://drkiq:yourpassword@postgres:5432/drkiq?encoding=utf8&pool=5&timeout=5000 CACHE_URL=redis://redis:6379/0 JOB_WORKER_URL=redis://redis:6379/0

Dockerized project Link here!

any idea how to convert the .env file to a format that can be used with kubernetes kompose

Docker-compose file:

  postgres:
    image: postgres:9.4.5
    environment:
      POSTGRES_USER: drkiq
      POSTGRES_PASSWORD: yourpassword
    ports:
      - '5432:5432'
    volumes:
      - drkiq-postgres:/var/lib/postgresql/data

  redis:
    image: redis:3.0.5
    ports:
      - '6379:6379'
    volumes:
      - drkiq-redis:/var/lib/redis/data

  drkiq:
    build: .
    links:
      - postgres
      - redis
    volumes:
      - .:/drkiq
    ports:
      - '8000:8000'
    env_file:
      - .drkiq.env
  sidekiq:
    build: .
    command: bundle exec sidekiq -C config/sidekiq.yml
    links:
      - postgres
      - redis
    volumes:
      - .:/drkiq
    env_file:
      - .drkiq.env
yivi
  • 42,438
  • 18
  • 116
  • 138
zewOlF
  • 403
  • 3
  • 8
  • 13

1 Answers1

2

Kubernetes kompose supports env_file conversion from Docker Compose 3.x version as it's described in Conversion matrix.

In Kubernetes you can use ConfigMap to store your environment variables from env_file. For SECRET_TOKEN variable, you can use Secrets to hold your private and sensitive data.

You can also check other tools for conversion purpose like compose2kube or k8s-env-gen.

According to the attached Docker-composer file and the error during the conversion process, I can assume that you missed image key value for drkiq and sidekiq services:

Update: docker-compose.yml file

version: '2'

services:
  postgres:
    image: postgres:9.4.5
    environment:
      POSTGRES_USER: drkiq
      POSTGRES_PASSWORD: yourpassword
    ports:
      - '5432:5432'
    volumes:
      - drkiq-postgres:/var/lib/postgresql/data

  redis:
    image: redis:3.0.5
    ports:
      - '6379:6379'
    volumes:
      - drkiq-redis:/var/lib/redis/data

  drkiq:
    build: .
    image: drkiq:tag
    links:
      - postgres
      - redis
    volumes:
      - .:/drkiq
    ports:
      - '8000:8000'
    env_file:
      - .drkiq.env
  sidekiq:
    build: .
    command: bundle exec sidekiq -C config/sidekiq.yml
    image: sidekiq:tag
    links:
      - postgres
      - redis
    volumes:
      - .:/drkiq
    env_file:
      - .drkiq.env
Nick_Kh
  • 5,089
  • 2
  • 10
  • 16
  • i added the image key value and i got an error `ERRO Could not parse config for project drkiq : Service 'drkiq' has both an image and build path specified. A service can either be built to image or use an existing image, not both. FATA composeObject.Parse() failed, Failed to load compose file: Service 'drkiq' has both an image and build path specified. A service can either be built to image or use an existing image, not both. ` – zewOlF Jul 26 '18 at 19:25
  • @zewOlF You need to specify `version` parameter in your docker-compose.yml file to avoid mentioned error. I've updated my answer to reflect this. – Nick_Kh Jul 27 '18 at 13:13
  • i got this error i am not sure why is this `FATA Error while deploying application: k.Transform failed: Unable to build Docker image for service drkiq: Unable to build image. For more output, use -v or --verbose when converting.: The command '/bin/sh -c bundle install' returned a non-zero code: 139 ` – zewOlF Jul 30 '18 at 08:26
  • @zewOlF Try to run your project with `docker-compose up` in order to check consistency of the build objects and in case of issues capture logs. – Nick_Kh Aug 02 '18 at 12:16