<p>I configured kubernetes cluster with one master and 4 worker nodes using KUBEADM tool IN LOCAL. All nodes are running fine. deployed an app and able access that app from browser. I have tried many ways to create a dashboard using kubectl but i am failed.</p>

<p><strong>TRY1:</strong> tried directly with the below command:</p>

<pre><code>$ sudo kubectl proxy --address="172.20.22.101" -p 8001 
</code></pre>

<p>tried to access the dashboard using the url <a href="http://172.20.22.101:8001/api/v1" rel="nofollow noreferrer">http://172.20.22.101:8001/api/v1</a>, but it is saying unauthorized.</p>

<p><strong>TRY2:</strong> created dashboard-admin.yaml file with the below content:</p>

<pre><code>apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
   name: kubernetes-dashboard
   labels:
     k8s-app: kubernetes-dashboard
roleRef:
   apiGroup: rbac.authorization.k8s.io
   kind: ClusterRole
   name: cluster-admin
subjects:
-  kind: ServiceAccount
   name: kubernetes-dashboard
   namespace: kube-system
</code></pre>

<p>And run the below command:</p>

<pre><code>$ kubectl create -f dashboard-admin.yaml
</code></pre>

<p>It's shown me: <code>clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created.</code></p>

<p>Running the below command: </p>

<pre><code>$ sudo kubectl proxy --address="172.20.22.101" -p 443
</code></pre>

<p>its running fine. I am accessing the <a href="http://172.20.22.101:443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/" rel="nofollow noreferrer">http://172.20.22.101:443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/</a> URL from browser. it's showing same unauthorized error.</p>

<p>run kubectl proxy command  with <strong>--accept-hosts</strong> option </p>

<pre><code> kubectl proxy --address="172.20.22.101" -p 8001  --accept-hosts="^*$"
</code></pre>

<p>and it will work fine.</p>

<p><strong>Note: this is not recommended for production grade kubernetes clusters, since you're accessing the dashboard through plain http.</strong></p>

<p>More secure alternative is to run access the dashboard through ssh tunnel like this.</p>

<p>in one terminal run:</p>

<pre><code>kubectl proxy 
</code></pre>

<p>in another terminal run a ssh tunnel to localhost:8001 (the default kubernetes dashboard port)</p>

<pre><code>ssh -NT -l SSH_USER -p SSH_PORT K8S_CONTROLLER_IP_ADDR -L 8001:localhost:8001
</code></pre>
