Skip to main content
Skip table of contents

GitLab Runner: Step-by-Step Guide

What to Do

To integrate GitLab with your Kubernetes cluster using KubeDNA, follow these steps:

  • Configure a GitLab runner in your environment.

  • Configure kubeconfig in your GitLab environment variables.


Configuring GitLab Runner: Step-by-Step Guide

  1. Navigate to the Home Page and select your cluster.

  2. Go to CI/CD and click Add GitLab.

  3. Select the architecture you want to use (ARM or x86).

  4. Choose the machine type you want to use (Note: This is based on the datacenter you are using).

  5. Enter your GitLab Registration Token (you can copy this from GitLab.com – click here for instructions).

  6. Click Save.

Once you save, KubeDNA will spin up a new resource inside your environment to configure a GitLab Runner named:

CODE
kubedna-<clustername>-<architecture>

This will also be the default tag for the runner inside your GitLab project. You can change it later within GitLab settings.


Configure Kubeconfig as a File Variable

  1. Download the kubeconfig file from Access & Security in the KubeDNA dashboard.

  2. Go to your GitLab project or subgroup settings.

  3. Create a variable (e.g., variable name: KUBECONFIG).

  4. Select type: File.

  5. Paste the contents of the downloaded kubeconfig file into the variable’s value.

  6. Save the variable.

Now you are ready to run GitLab pipelines!


Example .gitlab-ci.yml File

CODE
stages:
  - deploy

deploy:
  image: google/cloud-sdk:latest  # Google Cloud SDK with kubectl
  stage: deploy
  before_script:
    - export KUBECONFIG=/builds/remefox/demo.tmp/KUBECONFIG
  script:
    - kubectl apply -f deployment/
  only:
    - main
  environment:
    name: production
  when: manual
  tags:
    - kubedna-wade-x86 # this can be change in gitlab runner config 

Deployment Folder Structure

Inside the deployment/ folder, you should have three YAML files:

deployment.yml

CODE
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-kubernetes
        image: paulbouwer/hello-kubernetes:1.8
        ports:
        - containerPort: 8080
        env:
        - name: MESSAGE
          value: I just deployed this app with the help of KubeDNA

service.yml

CODE
apiVersion: v1
kind: Service
metadata:
  name: hello-world-service
spec:
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: 8080
  selector:
    app: hello-world

ingress.yml

CODE
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-world-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx-intern
  rules:
  - host: demo.kubedna.io
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: hello-world-service
            port:
              number: 80

Demo

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.