Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes dashboard showing Unauthorized [closed]

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.

TRY1: tried directly with the below command:

$ sudo kubectl proxy --address="172.20.22.101" -p 8001 

tried to access the dashboard using the url http://172.20.22.101:8001/api/v1, but it is saying unauthorized.

TRY2: created dashboard-admin.yaml file with the below content:

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

And run the below command:

$ kubectl create -f dashboard-admin.yaml

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

Running the below command:

$ sudo kubectl proxy --address="172.20.22.101" -p 443

its running fine. I am accessing the http://172.20.22.101:443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/ URL from browser. it's showing same unauthorized error.

like image 801
samba Avatar asked Dec 31 '25 14:12

samba


1 Answers

run kubectl proxy command with --accept-hosts option

 kubectl proxy --address="172.20.22.101" -p 8001  --accept-hosts="^*$"

and it will work fine.

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

More secure alternative is to run access the dashboard through ssh tunnel like this.

in one terminal run:

kubectl proxy 

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

ssh -NT -l SSH_USER -p SSH_PORT K8S_CONTROLLER_IP_ADDR -L 8001:localhost:8001
like image 56
Mohamed Ali Avatar answered Jan 04 '26 16:01

Mohamed Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!