Developing with a GKE cluster

This guide creates a Google Kubernetes Engine (GKE) cluster for chart development, deploys GitLab from your branch, and removes everything again when you are done.

Use a GKE cluster when your change depends on behavior that a local cluster does not provide, like cloud load balancers or persistent disks. For more information, see provider-specific testing.

Prerequisites

  • Install the required developer tools.

  • Install the Google Cloud CLI and the gke-gcloud-auth-plugin component that kubectl uses to authenticate:

    shell
    gcloud components install gke-gcloud-auth-plugin
  • Get access to a Google Cloud project where you can create GKE clusters and compute addresses. GitLab team members can create a personal project in the Sandbox Cloud.

  • Sign in with the Google Cloud CLI:

    shell
    gcloud auth login

Create the cluster

  1. Set the variables used by the following commands:

    shell
    export PROJECT="<your-project-id>"
    export REGION="us-central1"
    export ZONE="${REGION}-b"
    export CLUSTER_NAME="gitlab-dev-<your-name>"

    The cluster name must contain only lowercase letters, numbers, and hyphens.

  2. List the Kubernetes versions available in the zone:

    shell
    gcloud container get-server-config --project "${PROJECT}" --zone "${ZONE}" \
      --flatten="channels" \
      --filter="channels.channel=REGULAR" \
      --format="yaml(channels.channel,channels.defaultVersion,channels.validVersions)"

    Pick a version from a supported Kubernetes release.

  3. Create the cluster:

    shell
    gcloud container clusters create "${CLUSTER_NAME}" \
      --project "${PROJECT}" \
      --zone "${ZONE}" \
      --release-channel regular \
      --cluster-version "<version>" \
      --machine-type n2d-standard-4 \
      --num-nodes 2 \
      --enable-autoscaling --min-nodes 1 --max-nodes 4

    Two n2d-standard-4 nodes provide 8 vCPU and 32 GB of RAM, which meets the cluster requirements. To reduce costs, add --spot to use Spot VMs. GKE can reclaim Spot VMs at any time, so pods restart more often.

  4. Connect kubectl to the cluster. The create command already configures the current context, so you only need this step on another machine or after you switch contexts:

    shell
    gcloud container clusters get-credentials "${CLUSTER_NAME}" --project "${PROJECT}" --zone "${ZONE}"
    kubectl get nodes

Reserve an external IP

Reserve a static IP for the GitLab Gateway. The IP must be regional and in the same region as the cluster:

shell
gcloud compute addresses create "${CLUSTER_NAME}-external-ip" --project "${PROJECT}" --region "${REGION}"
export EXTERNAL_IP=$(gcloud compute addresses describe "${CLUSTER_NAME}-external-ip" \
  --project "${PROJECT}" --region "${REGION}" --format='value(address)')

This guide uses nip.io to resolve gitlab.${EXTERNAL_IP}.nip.io to the IP, so you don’t need to create DNS records.

Deploy GitLab

  1. From the root of the chart repository, set up the external dependencies:

    shell
    bash scripts/dev_dependencies.sh setup
  2. Deploy the chart from your branch:

    shell
    helm dependency update
    helm upgrade --install gitlab . \
      --namespace gitlab \
      --timeout 600s \
      -f .values/dev-external.values.yaml \
      --set global.hosts.domain="${EXTERNAL_IP}.nip.io" \
      --set global.hosts.externalIP="${EXTERNAL_IP}" \
      --set certmanager-issuer.email="<your-email>"

    If Let’s Encrypt cannot issue certificates for the domain, for example because of rate limits, you can attempt --set global.hosts.domain="${EXTERNAL_IP}.sslip.io", or use the auto-generated self-signed wildcard certificate instead.

  3. Open https://gitlab.${EXTERNAL_IP}.nip.io, or https://gitlab.${EXTERNAL_IP}.sslip.io if you switched to sslip.io, and sign in.

For more information about deploying a development branch, see Deploy development branch.

Clean up

Delete the cluster when you are done. Uninstall GitLab and delete the namespace first, so that GKE also deletes the load balancer and the persistent disks that the chart created:

shell
helm uninstall gitlab --namespace gitlab
bash scripts/dev_dependencies.sh teardown
kubectl delete namespace gitlab
gcloud container clusters delete "${CLUSTER_NAME}" --project "${PROJECT}" --zone "${ZONE}" --quiet
gcloud compute addresses delete "${CLUSTER_NAME}-external-ip" --project "${PROJECT}" --region "${REGION}" --quiet

To find leftover persistent disks, run:

shell
gcloud compute disks list --project "${PROJECT}" --filter="name~^pvc-"