Skip to content

Support extra hosts for kubernetes with host alises

Description

The [runners.docker] section have extra_hosts option to configure hosts file.

https://gitlab.com/gitlab-org/gitlab-runner/blob/master/docs/configuration/advanced-configuration.md#the-runnersdocker-section extra_hosts specify hosts that should be defined in a container environment

kubernets has HostAliases to do same thing:

https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/

  hostAliases:
  - ip: "127.0.0.1"
    hostnames:
    - "foo.local"
    - "bar.local"
  - ip: "10.1.2.3"
    hostnames:
    - "foo.remote"
    - "bar.remote"

I'm using /etc/hosts to resolve my gitlab host name, and encounter Couldn't resolve host 'gitlab.myhost.com'

Running with gitlab-runner 10.0.2 (a9a76a50)
  on Kubernetes Runner (e5d51f58)
Using Kubernetes namespace: gitlab
Using Kubernetes executor with image busybox:latest ...
Waiting for pod gitlab/runner-e5d51f58-project-87-concurrent-0ctv75 to be running, status is Pending
Waiting for pod gitlab/runner-e5d51f58-project-87-concurrent-0ctv75 to be running, status is Pending
Running on runner-e5d51f58-project-87-concurrent-0ctv75 via gitlab-runner-5d678545dc-wv9n2...
Cloning repository...
Cloning into '/docker/gitlab-runner'...
fatal: unable to access 'https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.myhost.com/docker/gitlab-runner.git/': Couldn't resolve host 'gitlab.myhost.com'
ERROR: Job failed: error executing remote command: command terminated with non-zero exit code: Error executing in Docker Container: 1

Proposal

Links to related issues and merge requests / references

Please paste a link of the related issues or/and merge requests

Edited by Steve Xuereb