<p>I am unable to get list of namespaces using rest api and rest end point is <code>https://&lt;localhost&gt;:8001/api/v1/namespaces</code></p>

<p>Using <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#list-namespace-v1-core" rel="nofollow noreferrer">this kubernetes document</a>:</p>

<p>I am using postman. I will repeat the steps:</p>

<ol>
<li>Created a user and given cluster admin privileges: </li>
</ol>

<p><code>kubectl create serviceaccount exampleuser</code></p>

<ol start="2">
<li>Created a rolebinding for our user with cluster role cluster-admin: </li>
</ol>

<p><code>kubectl create rolebinding &lt;nameofrolebinding&gt; --clusterrole cluster-admin 
      --serviceaccount default:exampleuser</code></p>

<ol start="3">
<li>Checked rolebinding using: </li>
</ol>

<p><code>kubectl describe rolebinding &lt;nameofrolebinding&gt;</code></p>

<ol start="4">
<li>Now by using:</li>
</ol>

<p><code>kubectl describe serviceaccount exampleuser
 kubectl describe secret exampleuser-xxxx-xxxx</code> </p>

<p>I will use token I got here to authenticate postman.</p>

<pre><code>GET https://&lt;ipofserver&gt;:port/api/v1/namespace
</code></pre>

<p>AUTH using bearer token.</p>

<p>Expected result to list all namespaces in cluster. like
<code>kubectl get namespaces</code>. But got a warning as follows.</p>

<pre><code>{
    "kind": "Status",
    "apiVersion": "v1",
    "metadata": {},
    "status": "Failure",
    "message": "namespaces is forbidden: User \"system:serviceaccount:default:exampleuser\" cannot list resource \"namespaces\" in API group \"\" at the cluster scope",
    "reason": "Forbidden",
    "details": {
        "kind": "namespaces"
    },
    "code": 403
}
</code></pre>

<p>I have used "cluster-admin" clusterrole for the user, still getting authentication related error.
please help.</p>

naveen kumar
<p>You should use <code>clusterrolebinding</code> instead of <code>rolebinding</code>: </p>

<pre><code>kubectl create clusterrolebinding &lt;nameofrolebinding&gt; --clusterrole cluster-admin --serviceaccount default:exampleuser
</code></pre>

<p><code>RoleBinding</code> means permissions to a namespaced resources, but <code>namespace</code> is not a <code>namespaced</code> resources, you can check this by <code>kubectl api-resouces</code>. </p>

<p>More detail at <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/#rolebinding-and-clusterrolebinding" rel="nofollow noreferrer">rolebinding-and-clusterrolebinding</a>: </p>

<blockquote>
  <p>Permissions can be granted within a namespace with a RoleBinding, or cluster-wide with a ClusterRoleBinding</p>
</blockquote>
