Using GitLab registry with a Kubernetes Cluster
This post gives information on how to pull private Docker images stored in the GitLab container registry into a Kubernetes deployment
Assumptions
- kubectl is already configured to connect to the correct cluster
1. Create GitLab credentials
To pull private images from the GitLab registry you will need to create an Access Token
- Visit https://gitlab.com/profile/personal_access_tokens
- Enter a token name, and optional expiry date
- Ensure
read_registry
is selected - Click “Create personal access token”
- Make a note of the token, it will not be shown again
2. Create a Secret
Create a secret using data from, replacing the placeholders with your GitLab username, GitLab access token and email address
kubectl create secret docker-registry gitlab-auth \
--docker-server=https://registry.gitlab.com \
--docker-username=USERNAME \
--docker-password=TOKEN \
--docker-email=EMAIL
Note: By default, Kubernetes secret data is not secure
3. Update your deployment
In your Deployment definition
spec:
template:
spec:
containers:
- image: registry.gitlab.com/user-name/image-name:tag
imagePullSecrets:
- name: gitlab-auth