<p>I am new to kubernetes and GCP. I am trying to deploy locally. I have an image that it is in a private repository in Google Registry.</p>
<p>I was able to deploy in a GCP cluster, but locally I am getting <code>ErrImagePull</code> when I try to apply the deployment.</p>
<p>I tried the following steps</p>
<ol>
<li><p>Created a <code>Service Account</code> with the role <code>Viewer</code> and downloaded the json file</p>
</li>
<li><p>I encoded the file with the following command <code>openssl base64 -in file.json -out encodedfile.json</code></p>
</li>
<li><p>I removed the return characters on the encoded file (to have the encoded content in one line)</p>
</li>
<li><p>I created a secret with a yaml to be able to access the docker Registry, and pasted the content of the encoded file on <code>.dockerconfigjson</code></p>
<p>apiVersion: v1
kind: Secret
metadata:
name: gcr-json-key
namespace: development
data:
.dockerconfigjson: xxxxx
type: kubernetes.io/dockerconfigjson</p>
</li>
<li><p>In the deployment I added</p>
<p>imagePullSecrets:</p>
<ul>
<li>name: gcr-json-key</li>
</ul>
</li>
</ol>
<p>I am getting the same error, it is not able to pull from the private google registry into my local machine</p>
<hr />
<p>UPDATE 1</p>
<p>I encoded the json file with this command</p>
<pre><code>base64 -i myorg-8b8eea93246a.json -o encoded-myorg-8b8eea93246a.json
</code></pre>
<p>Then I checked that this encoded file works</p>
<pre><code>cat encoded-myorg-8b8eea93246a.json | docker login -u _json_key_base64 --password-stdin \
https://us-docker.pkg.dev
</code></pre>
<p>And it worked</p>
<pre><code>Login Succeeded
</code></pre>
<p>This is the yaml file I am using to create the secret</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: gcr-json-key
  namespace: development
data:
  .dockerconfigjson: &lt;XXXX content of encoded myorg-8b8eea93246a.json file XXXX&gt;
type: kubernetes.io/dockerconfigjson
</code></pre>
<p>And in the deployment I have</p>
<pre><code>...
spec:
  ...
  imagePullSecrets:
  - name: gcr-json-key
...
</code></pre>
<p>The deployment is created but the image is not pulled. In the <code>kubectl get all</code> I can see the status <code>ImagePullBackOff</code></p>
<p>When I do a describe to the pod</p>
<pre><code>Failed to pull image &quot;gcr.io/xxx/yyy&quot;: rpc error: code = Unknown desc = Error response from daemon: unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials.
</code></pre>

<p>You are on right path. You need to create secret for registry login. This works for me:</p>
<pre><code>kubectl create secret docker-registry &lt;secret_name&gt; --docker-server=&lt;your.registry.domain.name&gt; --docker-username=&lt;user&gt; --docker-password=&lt;password&gt; --docker-email=&lt;your_email&gt;
</code></pre>
<p>And then I use this secret for deployment:</p>
<pre><code>spec:
  replicas: 1
  strategy: 
    type: Recreate
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: server
    spec:
      imagePullSecrets:
        - name: &lt;secret_name&gt;

</code></pre>
