Skip to content

Add support for converting Docker Compose extra_hosts to Kubernetes hostAliases #2066

@kfess

Description

@kfess

What would you like to be added?

I would like to add support for converting Docker Compose's extra_hosts field to Kubernetes' hostAliases field in Pod specifications.

Currently, when a docker-compose.yaml file contains extra_hosts entries like:

services:
  web:
    image: nginx
    extra_hosts:
      - "example.com:192.168.1.100"
      - "test.local:10.0.0.5"

Kompose does not convert these entries during the conversion process. I propose that Kompose should convert them to the equivalent Kubernetes hostAliases configuration:

apiVersion: v1
kind: Pod
metadata:
  name: web
spec:
  hostAliases:
  - ip: "192.168.1.100"
    hostnames:
    - "example.com"
  - ip: "10.0.0.5"
    hostnames:
    - "test.local"

Why is this needed?

The extra_hosts field in Docker Compose is commonly used to add custom host-to-IP mappings to the container's /etc/hosts file. This is particularly useful for:

Without this feature, users must manually add hostAliases to their Kubernetes manifests after conversion, which reduces the automation benefits of using Kompose.
Supporting this conversion would make the migration path from Docker Compose to Kubernetes smoother and more complete.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions