<p>I have a GitLab CI pipeline configured to run on Kubernetes runner. Everything worked great until I tried to add services (<a href="https://docs.gitlab.com/ee/ci/services/mysql.html" rel="nofollow noreferrer">https://docs.gitlab.com/ee/ci/services/mysql.html</a>) for test job. The service hostname (eg.: <code>mysql</code>) cannot be resolved on kubernetes, resulting into the following error <code>dial tcp: lookup mysql on 10.96.0.10:53: no such host</code>. However, it works on docker runner, but that's just not what I want. Is there any way to </p>

<p>The job definition from <code>.gitlab-ci.yml</code>:</p>

<pre><code>test:
    stage: test
    variables:
        MYSQL_ROOT_PASSWORD: --top-secret--
        MYSQL_DATABASE: --top-secret--
        MYSQL_USER: --top-secret--
        MYSQL_PASSWORD: --top-secret--
    services:
      - mysql:latest
      - nats:latest
    script:
        - ping -c 2 mysql
        - go test -cover -coverprofile=coverage.prof.tmp ./...
</code></pre>

<p><strong>Edit:</strong></p>

<p>Logs from <code>runner-jd6sxcl7-project-430-concurrent-0g5bm8</code> pod show that the services started. There are 4 containers total inside the pod: <code>build</code>,<code>helper</code>,<code>svc-0</code> (mysql), <code>svc-1</code> (nats)</p>

<p><code>svc-0</code> logs show the mysql service started successfully:</p>

<pre><code>2019-12-09 21:52:07+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
2019-12-09 21:52:07+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2019-12-09 21:52:08+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.18-1debian9 started.
2019-12-09 21:52:08+00:00 [Note] [Entrypoint]: Initializing database files
2019-12-09T21:52:08.226747Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-12-09T21:52:08.233097Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.18) initializing of server in progress as process 46
</code></pre>

<p><code>svc-1</code> logs show the nats service started successfully as well:</p>

<pre><code>[1] 2019/12/09 21:52:12.876121 [INF] Starting nats-server version 2.1.2
[1] 2019/12/09 21:52:12.876193 [INF] Git commit [679beda]
[1] 2019/12/09 21:52:12.876393 [INF] Starting http monitor on 0.0.0.0:8222
[1] 2019/12/09 21:52:12.876522 [INF] Listening for client connections on 0.0.0.0:4222
[1] 2019/12/09 21:52:12.876548 [INF] Server id is NCPAQNFKKWPI67DZHSWN5EWOCQSRACFG2FXNGTLMW2NNRBAMLSDY4IYQ
[1] 2019/12/09 21:52:12.876552 [INF] Server is ready
[1] 2019/12/09 21:52:12.876881 [INF] Listening for route connections on 0.0.0.0:6222
</code></pre>

<p>This was a known issue with older versions of GitLab Runner (&lt; 12.8), or when running Kubernetes executor in older versions of Kubernetes (&lt; 1.7).</p>
<p>From the <a href="https://gitlab.com/gitlab-org/gitlab-runner/-/blob/main/docs/executors/kubernetes.md#L26" rel="nofollow noreferrer">Kubernetes executor documentation of GitLab Runner</a>:</p>
<blockquote>
<ul>
<li>Since GitLab Runner 12.8 and Kubernetes 1.7, the services are accessible via their DNS names. <strong>If you are using an older version you will have to use <code>localhost</code></strong>.</li>
</ul>
</blockquote>
<p>(emphasis mine)</p>
<p>It's important to keep in mind that the other restrictions and implications of the Kubernetes executor. From the same document:</p>
<blockquote>
<p>Note that when services and containers are running in the same Kubernetes
pod, they are all sharing the same localhost address.</p>
</blockquote>
<p>So, even if you're able to use the service specific hostname to talk to your service, it's all really <code>localhost</code> (127.0.0.1) underneath.</p>
<p>As such, keep in mind the other important restriction from the same document:</p>
<blockquote>
<ul>
<li>You cannot use several services using the same port</li>
</ul>
</blockquote>
<p>(thanks to <a href="https://stackoverflow.com/users/3154003/user3154003">@user3154003</a> for the link to the <a href="https://gitlab.com/gitlab-org/gitlab-runner/-/issues/2229" rel="nofollow noreferrer">GitLab Runner issue</a> in a <a href="https://stackoverflow.com/a/61046902/1273938">currently deleted answer</a> that pointed me in the right direction for this answer.)</p>
