Kubernetes Pull Secret¶
Allow your K3s cluster to pull game server Docker images from a private GitLab Container Registry using a Deploy Token.
Prerequisites¶
- A running K3s cluster (master node set up)
kubectlconfigured and pointing to your cluster- Access to the GitLab project that hosts the container registry
Overview¶
Kubernetes needs credentials to pull images from private registries. The flow is:
flowchart LR
A[GitLab Project] -- "Create Deploy Token\nread_registry" --> B[Deploy Token\nusername + password]
B -- "kubectl create secret" --> C[K8s Secret\ntype: dockerconfigjson]
C -- "Patch ServiceAccount" --> D[All pods can pull\nprivate images]
1 — Create a GitLab Deploy Token¶
- In GitLab, go to Project → Settings → Repository → Deploy Tokens.
-
Click Add token:
Field Value Name e.g. k8s-pullExpiration Optional — set if your security policy requires rotation Scopes Enable read_registryonly -
Click Create deploy token.
- Copy both values — you won't see the password again:
DEPLOY_TOKEN_USERNAME(e.g.gitlab+deploy-token-1234)DEPLOY_TOKEN_PASSWORD
Warning
Use a Deploy Token (read-only, project-scoped) for Kubernetes, not a Personal Access Token. Deploy Tokens have minimal permissions and can be revoked per-project without affecting your account.
2 — Create the Kubernetes Secret¶
Run the script from MIPScripts\kubes\config\:
Or click 03 Create Pull Secret in the MIP Control Panel (Kubes → Config).
The script prompts for your Deploy Token username and password, then:
- Deletes any existing
gitlabsecret so there are no stale credentials - Creates a fresh
docker-registrysecret namedgitlabin thedefaultnamespace - Patches both the
defaultandagones-sdkServiceAccounts withimagePullSecrets: [gitlab]— fleet pods can pull fromregistry.gitlab.comwithout addingimagePullSecretsto every fleet YAML
Once done, head back to Deploy Master Node to continue the setup.
Verify:
3 — Verify¶
Create a test pod or let Agones allocate a game server, then check:
In the events section, you should see:
If you see ImagePullBackOff or ErrImagePull, check:
- The deploy token has
read_registryscope - The secret was created in the correct namespace (
default) - The ServiceAccount was patched
Rotating the Token¶
When a deploy token expires or is revoked:
- Create a new deploy token in GitLab (step 1).
- Re-run
03-create-gitlab-pull-secret.sh(or 03 Create Pull Secret in the Control Panel) — it deletes and recreates the secret automatically. - The ServiceAccount patches don't need to change — they reference the secret by name.
- Existing pods keep running. New pods will use the updated credentials.
Quick Reference¶
| Step | How |
|---|---|
| Create / recreate secret + patch SAs | bash 03-create-gitlab-pull-secret.sh or Control Panel → 03 Create Pull Secret |
| Verify secret | kubectl get secret gitlab -n default |
| Verify SA patch | kubectl get serviceaccount default -n default -o jsonpath='{.imagePullSecrets}' |
| Delete secret manually | kubectl delete secret gitlab -n default |