<p>My DigitalOcean kubernetes cluster is unable to pull images from the DigitalOcean registry. I get the following error message:</p>
<pre><code>Failed to pull image &quot;registry.digitalocean.com/XXXX/php:1.1.39&quot;: rpc error: code = Unknown desc = failed to pull and unpack image 
&quot;registry.digitalocean.com/XXXXXXX/php:1.1.39&quot;: failed to resolve reference 
&quot;registry.digitalocean.com/XXXXXXX/php:1.1.39&quot;: failed to authorize: failed to fetch anonymous token: unexpected status: 401 Unauthorized
</code></pre>
<p>I have added the kubernetes cluster using DigitalOcean Container Registry Integration, which shows there successfully both on the registry and the settings for the kubernetes cluster.</p>
<p><a href="https://i.stack.imgur.com/hOkVJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hOkVJ.png" alt="enter image description here" /></a></p>
<p>I can confirm the above address `registry.digitalocean.com/XXXX/php:1.1.39 matches the one in the registry. I wonder if I’m misunderstanding how the token / login integration works with the registry, but I’m under the impression that this was a “one click” thing and that the cluster would automatically get the connection to the registry after that.</p>
<p>I have tried by logging helm into a registry before pushing, but this did not work (and I wouldn't really expect it to, the cluster should be pulling the image).</p>
<p>It's not completely clear to me how the image pull secrets are supposed to be used.</p>
<p>My helm deployment chart is basically the default for API Platform:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include &quot;api-platform.fullname&quot; . }}
  labels:
    {{- include &quot;api-platform.labels&quot; . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include &quot;api-platform.selectorLabels&quot; . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include &quot;api-platform.selectorLabels&quot; . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include &quot;api-platform.serviceAccountName&quot; . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}-caddy
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: &quot;{{ .Values.caddy.image.repository }}:{{ .Values.caddy.image.tag | default .Chart.AppVersion }}&quot;
          imagePullPolicy: {{ .Values.caddy.image.pullPolicy }}
          env:
            - name: SERVER_NAME
              value: :80
            - name: PWA_UPSTREAM
              value: {{ include &quot;api-platform.fullname&quot; . }}-pwa:3000
            - name: MERCURE_PUBLISHER_JWT_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ include &quot;api-platform.fullname&quot; . }}
                  key: mercure-publisher-jwt-key
            - name: MERCURE_SUBSCRIBER_JWT_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ include &quot;api-platform.fullname&quot; . }}
                  key: mercure-subscriber-jwt-key
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
            - name: admin
              containerPort: 2019
              protocol: TCP
          volumeMounts:
            - mountPath: /var/run/php
              name: php-socket
          #livenessProbe:
          #  httpGet:
          #    path: /
          #    port: admin
          #readinessProbe:
          #  httpGet:
          #    path: /
          #    port: admin
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
        - name: {{ .Chart.Name }}-php
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: &quot;{{ .Values.php.image.repository }}:{{ .Values.php.image.tag | default .Chart.AppVersion }}&quot;
          imagePullPolicy: {{ .Values.php.image.pullPolicy }}
          env:
            {{ include &quot;api-platform.env&quot; . | nindent 12 }}
          volumeMounts:
            - mountPath: /var/run/php
              name: php-socket
          readinessProbe:
            exec:
              command:
                - docker-healthcheck
            initialDelaySeconds: 120
            periodSeconds: 3
          livenessProbe:
            exec:
              command:
                - docker-healthcheck
            initialDelaySeconds: 120
            periodSeconds: 3
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      volumes:
      - name: php-socket
        emptyDir: {}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
</code></pre>
<p>How do I authorize the kubernetes cluster to pull from the registry? Is this a helm thing or a kubernetes only thing?</p>
<p>Thanks!</p>

Brettins
<p>The issue was that API Platform automatically has a default value for imagePullSecrets in the helm chart, which is</p>
<p><code>imagePullSecrets: []</code></p>
<p>in <a href="https://github.com/api-platform/api-platform/blob/e7c3973a8bef114d9a618b0589a1ea34b21c5603/helm/api-platform/values.yaml#L60" rel="nofollow noreferrer">values.yaml</a></p>
<p>So this seems to override kubernetes from accessing imagePullSecrets in the way that I expected. The solution was to add the name of the imagePullSecrets directly to the helm deployment command, like this:</p>
<p><code>--set &quot;imagePullSecrets[0].name=registry-secret-name-goes-here&quot;</code></p>
<p>You can view the name of your secret using <code>kubectl get secrets</code> like this:</p>
<p><code>kubectl get secrets</code></p>
<p>And the output should look something like this:</p>
<pre><code>NAME                                      TYPE                                  DATA   AGE                                              
default-token-lz2ck                       kubernetes.io/service-account-token   3      38d                                              
registry-secret-name-goes-here            kubernetes.io/dockerconfigjson        1      2d16h                                            
</code></pre>
