Aller au contenu

Fix: Digital Ocean Registry Authentication

Brouillon : cette page n'a pas encore été relue et peut être incomplète ou inexacte.

Kubernetes pods are getting ImagePullBackOff errors because the cluster doesn’t have credentials to pull from the Digital Ocean Container Registry.

Run the helper script:

Fenêtre de terminal
cd /Users/moise/projects/af-corp/kili-shops-microservices
./scripts/do-setup-registry-auth.sh afcorp

This will:

  • Create an image pull secret in your cluster
  • Show you the secret name (usually starts with registry-)

Edit helm/kili-shops/values-do.yaml and add the imagePullSecrets:

# At the top of the file, update global section
global:
imagePullPolicy: Always
imagePullSecrets:
- name: registry-afcorp # Use the secret name from step 1

If you have a frontend values file, edit kilimmanjaro/helm/kilimmanjaro-frontend/values-do.yaml:

frontend:
# ... existing config ...
imagePullSecrets:
- name: registry-afcorp # Same secret name
Fenêtre de terminal
# Backend
cd /Users/moise/projects/af-corp/kili-shops-microservices
helm upgrade kili-shops ./helm/kili-shops -f ./helm/kili-shops/values-do.yaml
# Frontend
cd /Users/moise/projects/af-corp/kilimmanjaro
helm upgrade kilimmanjaro ./helm/kilimmanjaro-frontend -f ./helm/kilimmanjaro-frontend/values-do.yaml
Fenêtre de terminal
# Check pods are pulling images successfully
kubectl get pods
# Check events for any pod
kubectl describe pod <pod-name>
# Should see "Successfully pulled image" messages

If the script doesn’t work, here’s the manual approach:

Fenêtre de terminal
# This creates the secret automatically
doctl registry kubernetes-manifest | kubectl apply -f -
# Check what was created
kubectl get secret -n default | grep registry
# Note the secret name (e.g., registry-afcorp)
Fenêtre de terminal
# Step 1: Login to registry
doctl registry login
# Step 2: Create secret from Docker config
kubectl create secret generic regcred \
--from-file=.dockerconfigjson=$HOME/.docker/config.json \
--type=kubernetes.io/dockerconfigjson \
--namespace=default
# Verify
kubectl get secret regcred
Fenêtre de terminal
# Get your Docker registry credentials
cat ~/.docker/config.json
# Create secret with explicit credentials
kubectl create secret docker-registry regcred \
--docker-server=registry.digitalocean.com \
--docker-username=<your-do-email> \
--docker-password=<your-do-api-token> \
--namespace=default

  1. Check the secret is in the right namespace:

    Fenêtre de terminal
    kubectl get secret -n default | grep registry
  2. Verify the secret name matches in values:

    Fenêtre de terminal
    # Check values file
    cat helm/kili-shops/values-do.yaml | grep -A2 imagePullSecrets
  3. Check the pod is using the secret:

    Fenêtre de terminal
    kubectl get pod <pod-name> -o yaml | grep -A5 imagePullSecrets
  1. Check the image exists:

    Fenêtre de terminal
    doctl registry repository list-v2
    doctl registry repository list-tags api-gateway
  2. Verify registry URL is correct:

    Fenêtre de terminal
    # Check deployment
    kubectl get deployment api-gateway -o yaml | grep image:
    # Should match your registry URL
    # registry.digitalocean.com/afcorp/api-gateway:latest
  3. Check registry authentication:

    Fenêtre de terminal
    # Try pulling manually
    docker pull registry.digitalocean.com/afcorp/api-gateway:latest
    # If this fails, re-authenticate
    doctl registry login

If you used a different secret name:

Fenêtre de terminal
# List all secrets
kubectl get secrets
# Update values-do.yaml with correct name
# Then redeploy
helm upgrade kili-shops ./helm/kili-shops -f ./helm/kili-shops/values-do.yaml

We added imagePullSecrets support to all deployment templates:

  1. Backend deployments (kili-shops-microservices/helm/kili-shops/templates/*-deployment.yaml):

    spec:
    {{- if .Values.global.imagePullSecrets }}
    imagePullSecrets:
    {{- toYaml .Values.global.imagePullSecrets | nindent 8 }}
    {{- end }}
  2. Frontend deployment (kilimmanjaro/helm/kilimmanjaro-frontend/templates/deployment.yaml):

    spec:
    {{- if .Values.frontend.imagePullSecrets }}
    imagePullSecrets:
    {{- toYaml .Values.frontend.imagePullSecrets | nindent 8 }}
    {{- end }}
  • Digital Ocean Container Registry is private
  • Kubernetes needs credentials to pull images
  • The imagePullSecrets tells Kubernetes which secret contains the credentials
  • Without it, pods get ImagePullBackOff errors

For future deployments, always:

  1. Create registry secret first:

    Fenêtre de terminal
    ./scripts/do-setup-registry-auth.sh
  2. Add to values files before deploying:

    global:
    imagePullSecrets:
    - name: registry-afcorp
  3. Verify images are accessible:

    Fenêtre de terminal
    docker pull registry.digitalocean.com/afcorp/api-gateway:latest

Fenêtre de terminal
# List secrets
kubectl get secrets
# Describe secret
kubectl describe secret registry-afcorp
# Check if pod is using it
kubectl get pod <pod-name> -o yaml | grep -A3 imagePullSecrets
Fenêtre de terminal
# Delete old secret
kubectl delete secret registry-afcorp
# Create new one
doctl registry kubernetes-manifest | kubectl apply -f -
Fenêtre de terminal
# After updating secret or values
kubectl rollout restart deployment/api-gateway
kubectl rollout restart deployment/shops
kubectl rollout restart deployment/users
kubectl rollout restart deployment/kilimmanjaro-frontend