<p>I have created a GKE Service Account.</p>
<p>I have been trying to use it within GKE, but I get the error:</p>
<pre><code>pods &quot;servicepod&quot; is forbidden: error looking up service account service/serviceaccount: serviceaccount &quot;serviceaccount&quot; not found
</code></pre>
<p>I have followed the setup guide in this <a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/authenticating-to-cloud-platform#gcloud_1" rel="nofollow noreferrer">documentation</a>.</p>
<p>1.Created a GCP Service Account called &quot;serviceaccount&quot;</p>
<p>2.I created, and downloaded the JSON key as key.json.</p>
<p>3.<code>kubectl create secret generic serviceaccountkey --from-file key.json -n service</code></p>
<p>4.Added the following items to my deployment:</p>
<pre><code>    spec:
      volumes:
      - name: serviceaccountkey
        secret:
          secretName: serviceaccountkey
      containers:
        volumeMounts:
        - name: serviceaccountkey
          mountPath: /var/secrets/google
        env:
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: /var/secrets/google/key.json
</code></pre>
<p>When I deploy this out, I get:
<code>pods &quot;service-7cdbcc67b9-&quot; is forbidden: error looking up service account service/serviceaccount: serviceaccount &quot;serviceaccount&quot; not found</code></p>
<p>I'm not sure what else to do to get this working, I've followed the guide and can't see anything that's been missed.</p>
<p>Any help on this would be greatly appreciated!</p>

<p>One of the reasons for getting this error can be if you have created a service account in one namespace and trying to use that service account only for another namespace.</p>
<p>We can resolve this error by rolebinding the service account with a new namespace. If the existing service account is in default namespace then you can use this YAML file with the new namespace for rolebinding.</p>
<pre><code>apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata: 
  name: kubernetes-enforce-default 
  namespace: &lt;new-namespace&gt;
roleRef: 
  apiGroup: rbac.authorization.k8s.io 
  kind: ClusterRole
  name: kubernetes-enforce 
subjects:
- kind: ServiceAccount
  name: kubernetes-enforce
  namespace: kube-system
</code></pre>
<p>Refer to this <a href="https://stackoverflow.com/questions/63283438/how-can-i-create-a-service-account-for-all-namespaces-in-a-kubernetes-cluster">similar issue</a> for more information.</p>
