我正在尝试将文档化的项目迁移到kubernetes,我已经使用Kompose来转换项目
kompose --file docker-compose.yml convert

当我在迁移文件后运行kompose up
我得到这个错误
$ kompose upWARN 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=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxWORKER_PROCESSES=1LISTEN_ON=0.0.0.0:8000DATABASE_URL=postgresql://drkiq:yourpassword@postgres:5432/drkiq?encoding=utf8&pool=5&timeout=5000CACHE_URL=redis://redis:6379/0JOB_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

最佳答案

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

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

您还可以检查其他用于转换目的的工具,例如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

09-11 23:46