Pull Docker Images from GitLab to DigitalOcean Kubernetes
To pull images from the GitLab Container Registry into your DigitalOcean Kubernetes cluster, follow these steps:
1. Create a GitLab Personal Access Token
- Log in to GitLab: Go to your GitLab instance and log in with your credentials.
- Access your profile settings: Click on your profile picture in the top-right corner and select "Settings".
- Navigate to Access Tokens: In the left sidebar, find and click "Access Tokens".
- Generate a new token:
- Name: Give your token a name.
- Scopes: Select at least the
read_registry
scope. - Expiry date: Optionally, set an expiry date.
- Create token: Click the "Create personal access token" button.
- Copy the token: Copy the generated token and store it securely. You won’t be able to see it again.
2. Create a Kubernetes Secret for the Docker Registry
You need to create a Kubernetes secret to store your Docker registry credentials. Replace the placeholders with your actual values.
kubectl create secret docker-registry gitlab-registry \
--docker-server=registry.gitlab.com \
--docker-username=<your_gitlab_username> \
--docker-password=<your_personal_access_token> \
--docker-email=<your_email>
3. Use the Secret in Your Kubernetes Deployment
When creating your Kubernetes deployments, reference the secret you just created to authenticate with the GitLab Container Registry.
Here’s an example of a deployment YAML file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: registry.gitlab.com/<your_gitlab_namespace>/<your_project>:<tag>
ports:
- containerPort: 80
imagePullSecrets:
- name: gitlab-registry
4. Apply the Deployment
Apply the deployment to your Kubernetes cluster:
kubectl apply -f deployment.yaml
Summary
- Generate a GitLab personal access token with
read_registry
scope. - Create a Kubernetes secret to store your GitLab registry credentials.
- Reference the secret in your deployment YAML file.
This should enable your Kubernetes cluster to pull images from the GitLab Container Registry successfully.