<p>I used below file to create service account</p>
<pre><code>apiVersion: v1
kind: ServiceAccount
metadata:
  name: sa-reader
  namespace: default

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: &quot;true&quot;
  name: reader-cr
rules:
- apiGroups:
  - &quot;&quot;
  resources:
  - '*'
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - extensions
  resources:
  - '*'
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - apps
  resources:
  - '*'
  verbs:
  - get
  - list
  - watch

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-only-rb
subjects:
- kind: ServiceAccount
  name: sa-reader
roleRef:
  kind: ClusterRole
  name: reader-cr
  apiGroup: rbac.authorization.k8s.io
</code></pre>
<p>The kubeconfig I created is something similar</p>
<pre><code>apiVersion: v1
kind: Config
preferences: {}

clusters:
- name: qa
  cluster:
    certificate-authority-data: ca
    server: https:/&lt;server&gt;:443

users:
- name: sa-reader
  user:
    as-user-extra: {}
    token: &lt;token&gt;

contexts:
- name: qa
  context:
    cluster: qa
    user: sa-reader
    namespace: default

current-context: qa
</code></pre>
<p>With this kubeconfig file, I am able to access resources in the default namespace but not any other namespace. How to access resources in other namespaces as well?</p>

Vikas Rathore
<p>You can operate on a namespace explicitly by using the <code>-n</code> (<code>--namespace</code>) option to <code>kubectl</code>:</p>
<pre><code>$ kubectl -n my-other-namespace get pod
</code></pre>
<p>Or by changing your default namespace with the <code>kubectl config</code> command:</p>
<pre><code>$ kubectl config set-context --current --namespace my-other-namespace
</code></pre>
<p>With the above command, all future invocations of <code>kubectl</code> will assume the <code>my-other-namespace</code> namespace.</p>
