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.
Quick Fix
Section intitulée « Quick Fix »Step 1: Create the Registry Secret
Section intitulée « Step 1: Create the Registry Secret »Run the helper script:
cd /Users/moise/projects/af-corp/kili-shops-microservices./scripts/do-setup-registry-auth.sh afcorpThis will:
- Create an image pull secret in your cluster
- Show you the secret name (usually starts with
registry-)
Step 2: Update Backend Values
Section intitulée « Step 2: Update Backend Values »Edit helm/kili-shops/values-do.yaml and add the imagePullSecrets:
# At the top of the file, update global sectionglobal: imagePullPolicy: Always imagePullSecrets: - name: registry-afcorp # Use the secret name from step 1Step 3: Update Frontend Values
Section intitulée « Step 3: Update Frontend Values »If you have a frontend values file, edit kilimmanjaro/helm/kilimmanjaro-frontend/values-do.yaml:
frontend: # ... existing config ... imagePullSecrets: - name: registry-afcorp # Same secret nameStep 4: Redeploy
Section intitulée « Step 4: Redeploy »# Backendcd /Users/moise/projects/af-corp/kili-shops-microserviceshelm upgrade kili-shops ./helm/kili-shops -f ./helm/kili-shops/values-do.yaml
# Frontendcd /Users/moise/projects/af-corp/kilimmanjarohelm upgrade kilimmanjaro ./helm/kilimmanjaro-frontend -f ./helm/kilimmanjaro-frontend/values-do.yamlStep 5: Verify
Section intitulée « Step 5: Verify »# Check pods are pulling images successfullykubectl get pods
# Check events for any podkubectl describe pod <pod-name>
# Should see "Successfully pulled image" messagesManual Method (Alternative)
Section intitulée « Manual Method (Alternative) »If the script doesn’t work, here’s the manual approach:
Method 1: Using doctl (Simplest)
Section intitulée « Method 1: Using doctl (Simplest) »# This creates the secret automaticallydoctl registry kubernetes-manifest | kubectl apply -f -
# Check what was createdkubectl get secret -n default | grep registry
# Note the secret name (e.g., registry-afcorp)Method 2: Manual Secret Creation
Section intitulée « Method 2: Manual Secret Creation »# Step 1: Login to registrydoctl registry login
# Step 2: Create secret from Docker configkubectl create secret generic regcred \ --from-file=.dockerconfigjson=$HOME/.docker/config.json \ --type=kubernetes.io/dockerconfigjson \ --namespace=default
# Verifykubectl get secret regcredMethod 3: Using Docker Credentials Directly
Section intitulée « Method 3: Using Docker Credentials Directly »# Get your Docker registry credentialscat ~/.docker/config.json
# Create secret with explicit credentialskubectl create secret docker-registry regcred \ --docker-server=registry.digitalocean.com \ --docker-username=<your-do-email> \ --docker-password=<your-do-api-token> \ --namespace=defaultTroubleshooting
Section intitulée « Troubleshooting »Secret exists but pods still can’t pull
Section intitulée « Secret exists but pods still can’t pull »-
Check the secret is in the right namespace:
Fenêtre de terminal kubectl get secret -n default | grep registry -
Verify the secret name matches in values:
Fenêtre de terminal # Check values filecat helm/kili-shops/values-do.yaml | grep -A2 imagePullSecrets -
Check the pod is using the secret:
Fenêtre de terminal kubectl get pod <pod-name> -o yaml | grep -A5 imagePullSecrets
ImagePullBackOff persists
Section intitulée « ImagePullBackOff persists »-
Check the image exists:
Fenêtre de terminal doctl registry repository list-v2doctl registry repository list-tags api-gateway -
Verify registry URL is correct:
Fenêtre de terminal # Check deploymentkubectl get deployment api-gateway -o yaml | grep image:# Should match your registry URL# registry.digitalocean.com/afcorp/api-gateway:latest -
Check registry authentication:
Fenêtre de terminal # Try pulling manuallydocker pull registry.digitalocean.com/afcorp/api-gateway:latest# If this fails, re-authenticatedoctl registry login
Wrong secret name
Section intitulée « Wrong secret name »If you used a different secret name:
# List all secretskubectl get secrets
# Update values-do.yaml with correct name# Then redeployhelm upgrade kili-shops ./helm/kili-shops -f ./helm/kili-shops/values-do.yamlUnderstanding the Fix
Section intitulée « Understanding the Fix »What Changed
Section intitulée « What Changed »We added imagePullSecrets support to all deployment templates:
-
Backend deployments (
kili-shops-microservices/helm/kili-shops/templates/*-deployment.yaml):spec:{{- if .Values.global.imagePullSecrets }}imagePullSecrets:{{- toYaml .Values.global.imagePullSecrets | nindent 8 }}{{- end }} -
Frontend deployment (
kilimmanjaro/helm/kilimmanjaro-frontend/templates/deployment.yaml):spec:{{- if .Values.frontend.imagePullSecrets }}imagePullSecrets:{{- toYaml .Values.frontend.imagePullSecrets | nindent 8 }}{{- end }}
Why This is Needed
Section intitulée « Why This is Needed »- Digital Ocean Container Registry is private
- Kubernetes needs credentials to pull images
- The
imagePullSecretstells Kubernetes which secret contains the credentials - Without it, pods get
ImagePullBackOfferrors
Prevention
Section intitulée « Prevention »For future deployments, always:
-
Create registry secret first:
Fenêtre de terminal ./scripts/do-setup-registry-auth.sh -
Add to values files before deploying:
global:imagePullSecrets:- name: registry-afcorp -
Verify images are accessible:
Fenêtre de terminal docker pull registry.digitalocean.com/afcorp/api-gateway:latest
Quick Reference
Section intitulée « Quick Reference »Check Secret
Section intitulée « Check Secret »# List secretskubectl get secrets
# Describe secretkubectl describe secret registry-afcorp
# Check if pod is using itkubectl get pod <pod-name> -o yaml | grep -A3 imagePullSecretsRecreate Secret
Section intitulée « Recreate Secret »# Delete old secretkubectl delete secret registry-afcorp
# Create new onedoctl registry kubernetes-manifest | kubectl apply -f -Force Pod Restart
Section intitulée « Force Pod Restart »# After updating secret or valueskubectl rollout restart deployment/api-gatewaykubectl rollout restart deployment/shopskubectl rollout restart deployment/userskubectl rollout restart deployment/kilimmanjaro-frontendSee Also
Section intitulée « See Also »- DEPLOY-DIGITAL-OCEAN.md - Full deployment guide
- Kubernetes ImagePullSecrets Docs
- Digital Ocean Registry Docs