Skip to content

Database Services drop or does not start on Kubernetes when using `command`

Summary

When adding command options for services with Runner on Kubernetes (installed via GitLab), database services does not appear to start and/or dies.

Steps to reproduce

  1. Add a K8 cluster to project and install Helm and Runner.
  2. Add a database service in .gitlab-ci.yml for a job (tested with MySQL and PostgreSQL).
  3. Add a command option. Tested with the basic CMD of the images (mysqld, postgres).
  4. Add a script in the CI/CD job to connect to the database service.

NOTE: Above setup works with Runner on Docker. It only fails in Kubernetes. Did not test with Kubernetes Executor outside of the GitLab integration.

Actual behavior

Job is unable to find database host and fails.

Expected behavior

Connects to appropriate service and passes tests.

Relevant logs and/or screenshots

PostgreSQL*:

psql: could not connect to server: Connection refused
	Is the server running on host "127.0.0.1" and accepting
	TCP/IP connections on port 5432?
ERROR: Job failed: error executing remote command: command terminated with non-zero exit code: Error executing in Docker Container: 1

MySQL:

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
ERROR: Job failed: error executing remote command: command terminated with non-zero exit code: Error executing in Docker Container: 1

Environment description

Runner installed on Kubernetes cluster completely from GitLab

Used GitLab Runner version

10.3.0

.gitlab-ci.yml:

testing:
    stage: deploy
    image: ubuntu:18.04
    services: 
        - name: postgres:latest
          command: ["postgres"]

        #- name: mysql:5.7
        #  command: ["mysqld"]
        
    variables:
        POSTGRES_DB: db
        POSTGRES_USER: user
        POSTGRES_PASSWORD: password
        
    #variables: 
    #    MYSQL_DATABASE: db
    #    MYSQL_ROOT_PASSWORD: password
    
    script:
        - apt-get update && apt-get install -y postgresql-client
        - PGPASSWORD=password psql db -U user -h 127.0.0.1 -c "\dt"
        #- apt-get update && apt-get install -y mysql-client
        #- mysql -h 127.0.0.1 -uroot -ppassword db -e "SHOW databases;"