kubernetes组合起来不支持的env_file密钥

时间:2018-07-25 17:41:26

标签: docker kubernetes docker-compose compose kompose

我正在尝试将已记录的项目迁移到kubernetes,我已经使用Kompose来转换项目

kompose --file docker-compose.yml convert

在迁移文件后运行kompose up时 我收到此错误

$ 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文件:

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项目链接here

任何想法如何将.env文件转换为可与kubernetes kompose一起使用的格式

Docker-compose文件:

  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

1 个答案:

答案 0 :(得分:0)

Kubernetes kompose支持Docker Compose 3.x版本中的Conversion matrix版本的env_file转换。

在Kubernetes中,您可以使用ConfigMap存储env_file中的环境变量。对于SECRET_TOKEN变量,您可以使用Secrets来保存您的私人和敏感数据。

您还可以检查其他用于转换目的的工具,例如compose2kubek8s-env-gen

根据所附的Docker-composer文件和转换过程中的错误,我可以假定您错过了drkiqsidekiq服务的图片键值:

更新:docker-compose.yml文件

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