Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languageyml
titleInsert NodePort
collapsetrue
spec:
   clusterIP: 10.107.65.54
   externalTrafficPolicy: Cluster
   ports:
      - nodePort: 30000	# <--- pay attention to this field
        port: 443
        protocol: TCP
        targetPort: 8443
   selector:
        k8s-app: kubernetes-dashboard
   sessionAffinity: None
   type: NodePort		# <--- Enter NodePort (pay attention to upper/lowercase letters) in place of ClusterIP
status:
   loadBalancer:

...

As you can see in the image, there are 2 ways to access the dashboard: one through the token, which we have already talked about, and the other through the Kubeconfig, that is the Kubernetes configuration file that you have saved in $HOME/.kube/config. Before being used, the file needs to be modified: the dashboard needs the user in the Kubeconfig file to have either username and password or token, but config, which is itself a copy of the admin.conf file, only has client-certificate. You can manually edit the config file to add the token or using the method below

Code Block
languagebash
titleAdd token in config
collapsetrue
# Extract the token and insert it into the $TOKEN variable (pay attention to the namespace)
$ TOKEN=$(kubectl -n <namespace> describe secret $(kubectl -n <namespace> get secret | grep admin-user | awk '{print $1}')| awk '$1=="token:"{print $2}')
# Add the token in correspondence of the <user>
$ kubectl config set-credentials <user> --token="${TOKEN}"

If you have done this correctly, the config file will look like this

Code Block
languageyml
titleConfig with token
collapsetrue
apiVersion: v1
clusters:
- cluster: