...
The user interface is not distributed by default. Installation is very simple, just run the following command (check here the version)
Code Block |
---|
language | bash |
---|
title | Install Dashboard |
---|
|
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.25.0/aio/deploy/recommended.yaml |
...
Code Block |
---|
language | yml |
---|
title | Insert NodePort |
---|
collapse | true |
---|
|
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 |
---|
language | bash |
---|
title | Add token in config |
---|
collapse | true |
---|
|
# 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 below (look at the token
field at the end of the file). To look at the new configuration, launch the command kubectl config view
Code Block |
---|
language | yml |
---|
title | Config with token |
---|
collapse | true |
---|
|
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://<IP>:<port>
name: <cluster_name>
contexts:
- context:
cluster: <cluster_name>
user: <user_name>
name: <name>
current-context: <current-context>
kind: Config
preferences: {}
users:
- name: <user_name>
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
token: <token> |