metalstack cloud

Software Delivery with GitLab

Installation

Once your cluster is set up and you have access to it, run the following command to find out its DNS hostname.

kubectl cluster-info
Kubernetes control plane is running at https://api.gitlab.f8e67080ba.k8s.metalstackcloud.io
CoreDNS is running at https://api.gitlab.f8e67080ba.k8s.metalstackcloud.io/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Your cluster’s DNS would be https://gitlab.f8e67080ba.k8s.metalstackcloud.io. Create the two files shown below. Change <cluster-dns> to your DNS. In our case that would be gitlab.f8e67080ba.k8s.metalstackcloud.io.

# gitlab.yaml
## The global properties are used to configure multiple charts at once.
## Extended documentation at doc/charts/globals.md
global:
  ## doc/installation/deployment.md#deploy-the-community-edition
  edition: ce
  ## doc/charts/globals.md#configure-host-settings
  hosts:
    domain: <cluster-dns> # add your domain
    https: true
    ssh: ~
    gitlab:
      name: git.<cluster-dns> # add your gitlab url
    registry:
      name: registry.<cluster-dns> # add your registry url

  ## doc/charts/globals.md#configure-ingress-settings
  ingress:
    configureCertmanager: false
    enabled: false

  ## doc/charts/globals.md#configure-gitaly-settings
  gitaly:
    enabled: true

  ## doc/charts/globals.md#configure-minio-settings
  minio:
    enabled: true

  ## Timezone for containers.
  time_zone: UTC

  ## GitLab agent server for Kubernetes
  kas:
    enabled: true

## End of global

upgradeCheck:
  enabled: true

## Installation & configuration of jetstack/cert-manager
certmanager:
  install: false

## doc/charts/nginx/index.md
## doc/architecture/decisions.md#nginx-ingress
## Installation & configuration of charts/nginx
nginx-ingress:
  enabled: false

## Installation & configuration of stable/prometheus
prometheus:
  install: false

## Configuration of Redis
## doc/architecture/decisions.md#redis
## doc/charts/redis
redis:
  install: true

## Installation & configuration of stable/prostgresql
postgresql:
  install: true

## Installation & configuration of gitlab/gitlab-runner
gitlab-runner:
  install: false
#default-webservice.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.provider: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: 512m
    nginx.ingress.kubernetes.io/proxy-connect-timeout: '15'
    nginx.ingress.kubernetes.io/proxy-read-timeout: '600'
    nginx.ingress.kubernetes.io/service-upstream: 'true'
    cert.gardener.cloud/purpose: managed
    dns.gardener.cloud/class: garden
    dns.gardener.cloud/dnsnames: git.<cluster-dns> # add your gitlab url
    dns.gardener.cloud/ttl: '180'
  name: gitlab-webservice-default
  namespace: gitlab
spec:
  ingressClassName: nginx
  rules:
    - host: git.<cluster-dns> # add your gitlab url
      http:
        paths:
          - backend:
              service:
                name: gitlab-webservice-default
                port:
                  number: 8181
            path: /
            pathType: Prefix
  tls:
    - hosts:
        - git.<cluster-dns> # add your gitlab url
      secretName: gitlab-wildcard-tls

Now create the gitlab namespace:

kubectl create ns gitlab

We will use the offical GitLab Helm Chart to deploy GitLab. To do this we will add the Gitlab repo.

helm repo add gitlab https://charts.gitlab.io/ 
helm repo update

Now we can install GitLab:

helm install -n gitlab gitlab  -f gitlab.yaml gitlab/gitlab

You can use the watch command to see if the installation has finished. It should look like this:

watch kubectl get po -n gitlab
NAME                                          READY   STATUS      RESTARTS      AGE
gitlab-gitaly-0                               1/1     Running     0             33m
gitlab-gitlab-exporter-dbd5776b9-q48lb        1/1     Running     0             33m
gitlab-gitlab-shell-7d75d9fc4-69n8w           1/1     Running     0             33m
gitlab-gitlab-shell-7d75d9fc4-zwmpm           1/1     Running     0             33m
gitlab-migrations-1-v52vc                     0/1     Completed   0             33m
gitlab-postgresql-0                           2/2     Running     0             33m
gitlab-redis-master-0                         2/2     Running     0             33m
gitlab-registry-6f949895-fqp22                1/1     Running     0             33m
gitlab-registry-6f949895-qk7qd                1/1     Running     0             33m
gitlab-sidekiq-all-in-1-v2-7745fdbd79-cx4d2   1/1     Running     0             33m
gitlab-toolbox-7b74469c7f-4xn7k               1/1     Running     0             33m
gitlab-webservice-default-6487899995-mvp6z    2/2     Running     0             33m
gitlab-webservice-default-6487899995-z2bw2    2/2     Running     0             33m

Next we want to access our GitLab. For that we need an ingress-controller and we have to create some ingresses:

kubectl create ns ingress-nginx \
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx \
helm install ingress-nginx -n ingress-nginx ingress-nginx/ingress-nginx --version 4.7.1 \
kubectl create -f default-webservice.yaml

Now you can access your GitLab under the URL that you specified https://git.gitlab.f8e67080ba.k8s.metalstackcloud.io:

NOTE: It may take some moments, before an IP plus DNS is added to the ingress and GitLab is reachable under this URL.

new project

You can log in with the root User. To get the password run the following command:

kubectl get secret gitlab-gitlab-initial-root-password -ojsonpath='{.data.password}' -n gitlab | base64 --decode ; echo

If you want, you can also expose your GitLab registry. Create below file and change <cluster-dns> to your DNS.:

# registry.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.provider: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: '0'
    nginx.ingress.kubernetes.io/proxy-buffering: 'off'
    nginx.ingress.kubernetes.io/proxy-read-timeout: '900'
    nginx.ingress.kubernetes.io/proxy-request-buffering: 'off'
    cert.gardener.cloud/purpose: managed
    dns.gardener.cloud/class: garden
    dns.gardener.cloud/dnsnames: registry.<cluster-dns> # add your registry url
    dns.gardener.cloud/ttl: '180'
  name: gitlab-registry
  namespace: gitlab
spec:
  ingressClassName: nginx
  rules:
    - host: registry.<cluster-dns> # add your registry url
      http:
        paths:
          - backend:
              service:
                name: gitlab-registry
                port:
                  number: 5000
            path: /
            pathType: Prefix
  tls:
    - hosts:
        - registry.<cluster-dns> # add your registry url
      secretName: registry-wildcard-tls

Then create the ingress for the registry:

kubectl create -f registry.yaml

To do CI/CD with GitLab we will activate a runner. For that append /admin to the URL and navigate to the runners page:

runner overview

Click on the button New instance runner and create a runner:

runner creation

It is important to check the Run untagged jobs field. After you created the runner you have to copy the runner token:

created runner

Write this token and your GitLab URL into the new runner.yaml file:

# runner.yaml
runnerToken: <your token> # put your runner token in
gitlabUrl: https://git.<cluster-dns> # add your gitlab url
rbac:
  create: true

Now you can install the runner:

helm install -n gitlab gitlab-runner -f runner.yaml gitlab/gitlab-runner

When the installation has finished you should see a working runner on your runners page:

working runner

Now you can create your first project. Something like this:

new project

When the project is created navigate to the pipeline editor:

new project

There you can add this yaml to create an example job:

stages:
  - test

test-job:
  stage: test
  script:
    - echo "Hello There

Commit the change and a successful job should be triggered:

job passed

Uninstall

helm uninstall ingress-nginx -n ingress-nginx \
kubectl delete --force ns ingress-nginx \
helm uninstall -n gitlab gitlab-runner \
helm uninstall -n gitlab  gitlab \
kubectl delete --force ns gitlab

Good job!

You've completed this developer guide. We have many more, so feel free to explore our other guides! Should you have any questions about our products or need help with metalstack.cloud, please reach out to us anytime.