<p>I'm trying to deploy Gitlab-runner(s) on Openshift/K8S, but can't succeed in having runners communicating with Gitlab (itself deployed in pods on OCP).</p>

<p>I followed couple of different instructions like these ones:</p>

<ul>
<li><a href="https://www.youtube.com/watch?v=EwbhA53Jpp4" rel="nofollow noreferrer">https://www.youtube.com/watch?v=EwbhA53Jpp4</a></li>
<li><a href="https://docs.gitlab.com/runner/install/kubernetes.html" rel="nofollow noreferrer">https://docs.gitlab.com/runner/install/kubernetes.html</a></li>
<li><a href="https://github.com/oprudkyi/openshift-templates/blob/master/gitlab-runner/gitlab-runner.yaml" rel="nofollow noreferrer">https://github.com/oprudkyi/openshift-templates/blob/master/gitlab-runner/gitlab-runner.yaml</a></li>
</ul>

<p>My gitlab-runner pod is starting properly, but it always receives HTTP 404 Not Found error messages.</p>

<p>Here is my toml config file:</p>

<pre><code># cat /etc/gitlab-runner/config.toml
concurrent = 6
check_interval = 0

[[runners]]
  name = "GitLab Runner"
  url = "http://gitlab-ce.MY_COMAIN.com/ci"
  token = "WHO_CARES?"
  executor = "kubernetes"
  [runners.kubernetes]
    namespace = "MINE"
    privileged = false
    host = ""
    cert_file = ""
    key_file = ""
    ca_file = ""
    image = ""
    cpus = ""
    memory = ""
    service_cpus = ""
    service_memory = ""
    helper_cpus = ""
    helper_memory = ""
    helper_image = ""
  [runners.cache]
    Type = "s3"
    ServerAddress = "minio-service:80"
    AccessKey = "GENERATED"
    SecretKey = "GENERATED"
    BucketName = "bkt-gitlab-runner"
    Insecure = true
</code></pre>

<p>And as soon as the pod starts, I have this in my logs:</p>

<pre><code>Starting multi-runner from /etc/gitlab-runner/config.toml ...  builds=0
Running in system-mode.                            

Configuration loaded                                builds=0
Metrics server disabled                            
WARNING: Checking for jobs... failed                runner=WHO_CARES? status=404 Not Found
WARNING: Checking for jobs... failed                runner=WHO_CARES? status=404 Not Found
WARNING: Checking for jobs... failed                runner=WHO_CARES? status=404 Not Found
</code></pre>

<p>And in Gitlab, in the runners page (<a href="https://gitlab-ce.MY_COMAIN.com/group/project/settings/ci_cd" rel="nofollow noreferrer">https://gitlab-ce.MY_COMAIN.com/group/project/settings/ci_cd</a>) there is no "Runners activated for this project".</p>

<p>I can log in to my pod in its terminal and launch <code>gitlab-runner register</code> to register a new runner</p>

<pre><code>/ # gitlab-runner register
Running in system-mode.

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
https://gitlab-ce.MY_COMAIN.com
Please enter the gitlab-ci token for this runner:
WHO_CARES?
Please enter the gitlab-ci description for this runner:
[dc-gitlab-runner-service-1-ktw6v]: test
Please enter the gitlab-ci tags for this runner (comma separated):
test
Registering runner... succeeded                     runner=WHO_CARES?
Please enter the executor: docker+machine, kubernetes, ssh, docker-ssh, parallels, shell, virtualbox, docker-ssh+machine, docker:
kubernetes
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
</code></pre>

<p>But when I try to run it... I'm facing the exact same issue.</p>

<pre><code>/ # gitlab-runner run
Starting multi-runner from /etc/gitlab-runner/config.toml ...  builds=0
Running in system-mode.

Configuration loaded                                builds=0
Metrics server disabled
WARNING: Checking for jobs... failed                runner=WHO_CARES? status=404 Not Found
WARNING: Checking for jobs... failed                runner=WHO_CARES? status=404 Not Found
</code></pre>

<p>Of course, I checked if I can access Gitlab from the Runner terminal, and it works</p>

<pre><code>/ # ping
BusyBox v1.27.2 (2018-06-06 09:08:44 UTC) multi-call binary.

Usage: ping [OPTIONS] HOST

/ # ping gitlab-ce.MY_COMAIN.com
PING gitlab-ce.MY_COMAIN.com (1.2.3.4): 56 data bytes
64 bytes from 1.2.3.4: seq=0 ttl=63 time=0.268 ms
64 bytes from 1.2.3.4: seq=1 ttl=63 time=0.261 ms
64 bytes from 1.2.3.4: seq=2 ttl=63 time=0.288 ms
^C
</code></pre>

<p>Side note: I'm running OCP 3.9 / K8S 1.9</p>

<p>Do you see anything I'm doing wrong?</p>

<p>Cheers,
Olivier</p>

<p>OK. Here is the solution.</p>

<p>The problem is coming from a weird behavior with the <code>token</code>. There are several <code>token</code> in Gitlab and one must choose carefuly the one to use.</p>

<p><strong>This problem is also related here: <a href="https://gitlab.com/gitlab-org/gitlab-ce/issues/37807" rel="nofollow noreferrer">https://gitlab.com/gitlab-org/gitlab-ce/issues/37807</a></strong></p>

<p>You must first use the Runner token available in the admin page: <a href="https://gitlab-instance/admin/runners" rel="nofollow noreferrer">https://gitlab-instance/admin/runners</a>. This token is to be used in your <code>config.toml</code>, under the [runners.token] section.</p>

<p>Deploy and start the runner.</p>

<p>It appears in Gitlab, but is unavailable. Simply clik on its name in the admin area: <a href="https://gitlab-instance/admin/runners/38" rel="nofollow noreferrer">https://gitlab-instance/admin/runners/38</a></p>

<p>Find here in the details the token associated to this Runner.</p>

<p>Copy it back to the <code>config.toml</code> file, still under the exact same [runners.token] section, as a replacement.
Redeploy your runner.</p>

<p>Should work.</p>
