Skip to content
subuilds.dev

← logbuild #27 passed0c2318d

Self-Host GitLab EE on K3s with Cloudflare Tunnel

A full homelab setup for GitLab EE on a single-node K3s VM. It covers split-horizon DNS, Cloudflare Tunnel, ARM64 image fixes, and the traps the official chart docs do not mention.

· 16 min read

The official GitLab Helm chart is made for production. It expects 8 vCPU, 30 GB RAM, many nodes, a registry on its own subdomain, and ports 80/443 open to the internet. A homelab on a Mac Mini cannot offer any of that. You want three things:

  • One URL that works the same on LAN (your home network) and WAN (the internet)
  • Zero inbound ports on the home router
  • A setup that fits in 6 vCPU / 12 GB and still leaves the machine usable

This post shows the real working configuration. It runs K3s on a Debian 13 ARM64 VM, with Traefik + cloudflared + cert-manager and Pi-hole split-horizon DNS. It also covers four traps that the docs do not mention. Each one can cost you hours if you do not expect it.

In Simple Words#

The problem
You want to run GitLab at home on one small VM. The official Helm chart expects a much bigger production cluster and open ports to the internet.
The root cause
The chart’s defaults are made for production: 8 vCPU, 30 GB RAM, many nodes and amd64 images. A 12 GB ARM64 VM with its own hostname breaks several of these defaults.
The solution
Turn off the optional parts so GitLab fits. Use Pi-hole DNS for the direct path at home, and a Cloudflare Tunnel for the path from outside. Then fix four traps: two old MinIO images, the hostname, and the homepage error.
Think of it like this
Your house has one address but two ways in. People who are already inside walk straight to the room. Visitors from outside come through a guarded corridor that you opened from the inside, so the front door stays locked.

What You’ll Cover#

  1. The architecture: what runs where, and which path each request takes
  2. How to get a certificate with DNS-01, cert-manager and a Cloudflare API token
  3. Split-horizon DNS on Pi-hole, so LAN traffic does not go out to Cloudflare and back
  4. Cloudflared as a Deployment inside the cluster, with no port forwarding at all
  5. A minimal values.yaml that runs on a 12 GB VM
  6. ARM64 image overrides for both the MinIO server and the mc client
  7. The hostname override the chart needs when your hostname isn’t gitlab.<domain>
  8. The GitLab Duo homepage error 500 on fresh installs, and how to get around it

Architecture#

  1. Two clients want gitlab.example.com. One is at home on the LAN. One is outside, on the internet.
  2. The LAN client asks Pi-hole for the name. Pi-hole answers with the VM’s LAN IP, 192.168.1.20.
  3. The LAN client connects straight to Traefik on the VM. Traefik passes the request to GitLab. Nothing leaves the house.
  4. The cloudflared pod opens an outbound QUIC tunnel to Cloudflare. The home router opens no inbound port.
  5. The remote client gets a Cloudflare address from public DNS. Its request goes through the tunnel to Traefik and GitLab.
5 / 5

Two request paths use the same hostname and the same Let’s Encrypt (LE) certificate:

  • LAN client → Pi-hole returns the VM’s LAN IP → Traefik on the VM → GitLab. The request never goes out to the internet.
  • Remote client → Cloudflare public DNS → Cloudflare edge → outbound QUIC tunnel → Traefik → GitLab. The cloudflared pod inside the cluster keeps this tunnel open. The home router never accepts an inbound connection.

One LE certificate covers gitlab.<your-domain>. cert-manager gets it with DNS-01 through the Cloudflare API. With DNS-01 you prove that you own the domain by writing a DNS record. So you need no HTTP-01, no open port 80, and no port forwarding.

Why This Stack#

Some of these choices look random. Each one has a reason:

Decision Reason
UTM, not OrbStack OrbStack always uses its own 192.168.139.x bridge, so the VM can’t get a real LAN IP on 192.168.1.0/24. UTM supports real bridged networking, so the VM is one more machine on the LAN.
K3s, not k0s or minikube Comes with Traefik + local-path-provisioner + ServiceLB already included. That is three fewer things to install. PVCs (storage volumes) are stored under /var/lib/rancher/k3s/storage/.
DNS-01, not HTTP-01 The VM does not have to be reachable on port 80 from the internet. The Cloudflare API token only needs Zone:Read + DNS:Edit on the zone.
Cloudflare Tunnel, not port forward No inbound ports on the home router. The tunnel is an outbound QUIC connection from inside the cluster to Cloudflare’s edge. It goes the same direction as any other outgoing traffic.
MinIO bundled, registry off GitLab needs object storage for artifacts/uploads/LFS. The Container Registry is optional. Pull images from Docker Hub or GHCR, and you can skip a second hostname and Ingress.

Prerequisites#

  • A running K3s cluster, where kubectl get nodes shows Ready
  • A domain on Cloudflare (this post uses example.com)
  • A Pi-hole at 192.168.1.2 where you can add local DNS records
  • At least 50 GB free under /var/lib/rancher/k3s/storage/

Install Helm (the package manager for Kubernetes) and add the GitLab chart:

bash
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
helm repo add gitlab https://charts.gitlab.io/
helm repo update

DNS-01 with cert-manager#

Create a Cloudflare API token. Give it Zone:Read + DNS:Edit on your zone only, and nothing else. Store it as a secret:

bash
kubectl create namespace cert-manager
kubectl create secret generic cloudflare-api-token \
  --namespace cert-manager \
  --from-literal=api-token='<paste-token>'

Install cert-manager and apply a ClusterIssuer. The ClusterIssuer tells cert-manager where and how to get certificates:

bash
helm repo add jetstack https://charts.jetstack.io
helm install cert-manager jetstack/cert-manager \
  --namespace cert-manager --create-namespace \
  --set crds.enabled=true
yaml
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: letsencrypt-cloudflare
spec:
  acme:
    server: https://acme-v02.api.letsencrypt.org/directory
    email: [email protected]
    privateKeySecretRef:
      name: letsencrypt-cloudflare-account-key
    solvers:
      - dns01:
          cloudflare:
            apiTokenSecretRef:
              name: cloudflare-api-token
              key: api-token
        selector:
          dnsZones: ["example.com"]

Create the Certificate before you install GitLab. Then the secret already exists when the Ingress starts:

yaml
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: gitlab-tls
  namespace: gitlab
spec:
  secretName: gitlab-tls
  issuerRef:
    name: letsencrypt-cloudflare
    kind: ClusterIssuer
  commonName: gitlab.example.com
  dnsNames:
    - gitlab.example.com
  privateKey:
    algorithm: ECDSA
    size: 256
  duration: 2160h    # 90d
  renewBefore: 360h  # 15d
bash
kubectl create namespace gitlab
kubectl apply -f gitlab-tls-cert.yaml
kubectl -n gitlab get certificate gitlab-tls -w
# wait for READY=True (typically 30–120s)

Split-Horizon DNS on Pi-hole#

Split-horizon DNS means that one name gets a different answer at home and outside. Most homelab guides skip this part. Without it, every LAN request to gitlab.example.com takes the long way. It goes out through your ISP, into Cloudflare, back through the tunnel, and into your VM. That is three hops to reach a machine that stands six feet from your desk.

The fix is one local DNS record. On the Pi-hole at 192.168.1.2, go to Settings → Local DNS Records → Add:

text
Domain:  gitlab.example.com
IP:      192.168.1.20    (your K3s VM's LAN IP)

The same record as dnsmasq config:

text
address=/gitlab.example.com/192.168.1.20

Reload with pihole restartdns. Check from a LAN client:

bash
dig @192.168.1.2 gitlab.example.com +short
# expected: 192.168.1.20   (NOT a Cloudflare anycast address)

Cloudflared in the Cluster#

Run these three setup commands once, from any machine that has cloudflared installed. A workstation is fine. The binary does not need to be on the K3s VM:

bash
cloudflared tunnel login
cloudflared tunnel create gitlab-homelab
cloudflared tunnel route dns gitlab-homelab gitlab.example.com

The create command writes credentials to ~/.cloudflared/<uuid>.json. Load them into the cluster:

bash
kubectl -n gitlab create secret generic cloudflared-credentials \
  --from-file=credentials.json=$HOME/.cloudflared/<tunnel-uuid>.json

Deploy cloudflared as a normal Kubernetes Deployment. It points at the Traefik service inside the cluster:

yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: cloudflared-config
  namespace: gitlab
data:
  config.yaml: |
    tunnel: <tunnel-uuid>
    credentials-file: /etc/cloudflared/creds/credentials.json
    ingress:
      - hostname: gitlab.example.com
        service: https://traefik.kube-system.svc.cluster.local:443
        originRequest:
          originServerName: gitlab.example.com   # MUST match a SAN on gitlab-tls
      - service: http_status:404
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: cloudflared
  namespace: gitlab
spec:
  replicas: 1
  selector:
    matchLabels: { app: cloudflared }
  template:
    metadata:
      labels: { app: cloudflared }
    spec:
      containers:
        - name: cloudflared
          image: cloudflare/cloudflared:latest
          args: ["tunnel", "--config", "/etc/cloudflared/config/config.yaml", "run"]
          volumeMounts:
            - { name: config, mountPath: /etc/cloudflared/config, readOnly: true }
            - { name: creds, mountPath: /etc/cloudflared/creds, readOnly: true }
      volumes:
        - { name: config, configMap: { name: cloudflared-config } }
        - { name: creds, secret: { secretName: cloudflared-credentials } }
bash
kubectl apply -f cloudflared.yaml
kubectl -n gitlab logs deploy/cloudflared
# expect: "Registered tunnel connection" lines, one per CF edge

In the Cloudflare dashboard, set the public hostname to proxied (orange cloud). Cloudflare ends the TLS connection at its edge with its own certificate. Then the tunnel encrypts the traffic again on the way to Traefik. Traefik shows the LE certificate inside the cluster. That’s why originServerName must match a SAN (a name listed in the certificate) on gitlab-tls. If it does not, Traefik’s SNI matching finds no match and serves the wrong certificate.

The Minimal values.yaml#

Save this as gitlab-values.yaml. It turns off everything optional, so GitLab can run on the 12 GB VM:

yaml
global:
  edition: ee
  hosts:
    domain: example.com
    # gitlab:
    #   name: gitlabee.example.com   # uncomment if your prefix isn't `gitlab.`
    https: true
  ingress:
    configureCertmanager: false
    class: traefik
    tls:
      enabled: true
      secretName: gitlab-tls
  initialRootPassword:
    secret: gitlab-initial-root-password
    key: password
  kas:
    enabled: false

nginx-ingress:
  enabled: false

prometheus:
  install: false
gitlab-runner:
  install: false
installCertmanager: false

registry:
  enabled: false
gitlab:
  webservice:
    minReplicas: 1
    maxReplicas: 1
    resources:
      requests: { cpu: 400m, memory: 2.5Gi }
  sidekiq:
    minReplicas: 1
    maxReplicas: 1
    resources:
      requests: { cpu: 200m, memory: 1Gi }
  gitaly:
    persistence:
      storageClass: local-path
      size: 20Gi

postgresql:
  persistence: { storageClass: local-path, size: 8Gi }
redis:
  master:
    persistence: { storageClass: local-path, size: 5Gi }

minio:
  image: quay.io/minio/minio
  imageTag: RELEASE.2025-09-07T16-13-09Z
  imagePullPolicy: IfNotPresent
  minioMc:
    image: quay.io/minio/mc
    tag: RELEASE.2025-09-07T16-02-50Z
  ingress:
    enabled: false
  persistence: { storageClass: local-path, size: 20Gi }

Create the root password secret first, so you don’t have to search for it later:

bash
kubectl create secret generic gitlab-initial-root-password \
  --namespace gitlab \
  --from-literal=password='ChangeMe-Strong-Password!'

Install:

bash
helm install gitlab gitlab/gitlab \
  --namespace gitlab \
  --values gitlab-values.yaml \
  --timeout 600s

kubectl -n gitlab get pods -w

The first install pulls several GB of images and runs database migrations. On a 6 vCPU ARM64 VM, plan for 15–20 minutes before gitlab-webservice-default-* is 2/2 Running.

Four Traps That Can Cost You Hours#

Everything above works on x86 with the default hostname. The four problems below appear on ARM64, with a non-default hostname, or on a fresh install.

ARM64 #1: The MinIO Server Image#

GitLab’s chart includes a MinIO subchart for object storage. It is fixed to RELEASE.2017-12-28T01-21-00Z, an amd64-only image from 2017. On ARM64 the pod fails with exec format error and never starts.

The fix is in the minio block above:

yaml
minio:
  image: quay.io/minio/minio
  imageTag: RELEASE.2025-09-07T16-13-09Z

quay.io/minio/minio is multi-arch: one image name works on more than one CPU type. The chart sets the env vars MINIO_ACCESS_KEY / MINIO_SECRET_KEY. Current MinIO still accepts them as old names for MINIO_ROOT_USER / MINIO_ROOT_PASSWORD. So the credentials keep working, and you change nothing else.

ARM64 #2: The MinIO mc Client Image#

This one is not in the official chart docs. The chart uses a separate fixed image for the mc client. The gitlab-minio-create-buckets Job runs this client:

text
registry.gitlab.com/gitlab-org/cloud-native/mirror/images/minio/mc:RELEASE.2018-07-13T00-53-22Z

This is an amd64-only image from 2018. On ARM64 the Job loops in CrashLoopBackOff, with three clear signs:

  • Exit code 255
  • Pod starts and exits in the same second
  • kubectl logs … --previous returns unable to retrieve container logs

The buckets are never created. So GitLab returns 500 on any page that uses object storage. That is most pages, including /dashboard/home. The webservice pods are 2/2 Running, the certificate is valid, and the tunnel is green on the Cloudflare dashboard. Everything looks fine, but nothing works.

The fix is the minioMc block in values.yaml above:

yaml
minio:
  minioMc:
    image: quay.io/minio/mc
    tag: RELEASE.2025-09-07T16-02-50Z

After a helm upgrade, make the Job run again with the new image:

bash
kubectl -n gitlab delete job -l component=create-buckets
kubectl -n gitlab get pods -l component=create-buckets -w
# expect: Completed

Then restart webservice + sidekiq, so they find the buckets that now exist:

bash
kubectl -n gitlab rollout restart \
  deploy/gitlab-webservice-default \
  deploy/gitlab-sidekiq-all-in-1-v2

Hostname Prefix: Override global.hosts.gitlab.name#

By default the chart builds the GitLab hostname as gitlab.<global.hosts.domain>. Say you set domain: example.com and point the tunnel at gitlabee.example.com (or git.example.com, or any name without the gitlab. prefix). Then Traefik gets an Ingress for the default name only. The tunnel returns 404 page not found on the hostname you really use.

The Cloudflare dashboard is green. The certificate is valid. The webservice is healthy. But Traefik has no Ingress that matches the Host header.

yaml
global:
  hosts:
    domain: example.com
    gitlab:
      name: gitlabee.example.com   # the actual hostname you serve

Verify after helm upgrade:

bash
kubectl -n gitlab get ingress
# HOSTS column must match the hostname in the cloudflared config AND the SAN on gitlab-tls

The same hostname must be in three places: global.hosts.gitlab.name, the cloudflared ConfigMap’s hostname + originServerName, and the gitlab-tls Certificate’s dnsNames. If one of the three is different, at least one path breaks.

The Duo Homepage 500 on Fresh Install#

On a fresh GitLab 17.x+, the first visit to /dashboard/home makes the controller create an internal bot user called duo_code_review_bot. The bot is not created at install time, only at this first visit. On fresh installs, saving that bot can fail. The homepage needs the bot’s username to render, so the whole page returns 500. /api/v4/user_counts returns 500 for the same reason.

The stack trace looks like this:

text
app/controllers/dashboard_controller.rb:50:in `home'
app/controllers/concerns/homepage_data.rb:21:in `homepage_app_data'
app/controllers/concerns/homepage_data.rb:66:in `duo_code_review_bot_username'
lib/users/internal.rb:110:in `duo_code_review_bot'
lib/users/internal.rb:241:in `create_unique_internal'
state_machines (0.100.4) lib/state_machines/machine.rb:569:in `save'

/dashboard/projects returns 200. So you are not locked out of GitLab. Only the new home view is broken.

The easiest way around it is to send users to the old dashboard:

For one user: Top-right avatar → Preferences → Homepage → Your Projects.

For the whole instance: Admin Area → Settings → Preferences → Navigation → Default dashboard → Your Projects.

To find the real root cause, run the same code in the Rails console. There the error prints clearly:

bash
kubectl -n gitlab exec -it deploy/gitlab-toolbox -- gitlab-rails runner '
  begin
    u = Users::Internal.duo_code_review_bot
    puts "OK: #{u.inspect}"
  rescue => e
    puts "FAILED: #{e.class}: #{e.message}"
    puts e.record.errors.full_messages if e.respond_to?(:record)
  end
'

Common causes:

  • An old row left by an earlier creation that stopped halfway
  • Email validation against an allowlist
  • A Duo setting that must be set first

When you have the validation error, the fix is usually one line.

Verify the End-to-End Path#

From a LAN device that uses Pi-hole as its DNS server:

bash
dig gitlab.example.com +short
# → 192.168.1.20   (VM, not Cloudflare)

curl -vI https://gitlab.example.com 2>&1 | grep -E "(issuer|cf-ray|server:)"
# expected: issuer=Let's Encrypt, NO cf-ray header

From outside the LAN (mobile data):

bash
dig gitlab.example.com +short
# → Cloudflare anycast

curl -vI https://gitlab.example.com 2>&1 | grep -E "(cf-ray|server:)"
# expected: cf-ray: <id>, server: cloudflare

Tunnel health:

bash
kubectl -n gitlab logs deploy/cloudflared --tail=50
# expect: "Registered tunnel connection" lines, no repeating errors

Certificate:

bash
kubectl -n gitlab get certificate gitlab-tls
# NAME         READY   SECRET       AGE
# gitlab-tls   True    gitlab-tls   3m

What You Have Now#

Component What it does
UTM + Debian 13 VM Real LAN IP, ARM64 kernel, single-node K3s
K3s + Traefik Single-binary Kubernetes with Ingress and storage included
cert-manager + DNS-01 One LE certificate for your GitLab hostname, and port 80 stays closed
cloudflared Deployment Outbound QUIC tunnel — zero inbound ports on the home router
Pi-hole local DNS LAN clients reach the VM directly, with no trip out to Cloudflare and back
GitLab Helm chart (minimal) EE image, Postgres + Redis + Gitaly + MinIO bundled, no registry/KAS/Prometheus/Runner
Single hostname Same URL, same certificate, on LAN and WAN. No /etc/hosts edits needed

The VM uses around 7–9 GB RAM at idle. The first boot takes 15–20 minutes. Later restarts take under a minute. Git over SSH works on the LAN (port 22 on the VM). From outside, use HTTPS with a Personal Access Token. Cloudflare Tunnel doesn’t expose plain SSH unless the client runs cloudflared access tcp.

Next Steps#