kompose icon indicating copy to clipboard operation
kompose copied to clipboard

Add support for converting Docker Compose extra_hosts to Kubernetes hostAliases

Open kfess opened this issue 1 month ago • 0 comments

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.

kfess avatar Nov 20 '25 10:11 kfess