![]() |
VOOZH | about |
Kubernetes - Dashboard Setup is a web-based user interface that offers a summary of your Kubernetes cluster. You may manage your resources using a graphical interface and view information about your pods, deployments, services, and more with the dashboard. How do you maintain track of all the containers you deploy using Kubernetes when there are hundreds of them? That won't work with a command-line interface. Everything must be represented visually. Welcome to the Kubernetes dashboard. The official web-based UI for Kubernetes, known as Kubernetes Dashboard, consists of a collection of services that make cluster management easier. You will discover how to set up the Kubernetes Dashboard on an Ubuntu computer step-by-step in this guide.
Kubernetes Dashboard is used to represent all the cluster components and resources in the form of a user interface (UI). Instead of using kubectl (Command line interface) to list the cluster resources, you can use the Kubernetes dashboard and watch in the form of UI. You can view the resources in the cluster and the Kubernetes dashboard will allow you to interact with the resources like pods, services, deployments, and some other resources.
It is not an replacement of kubectl.
The Kubernetes Dashboard is a web-based user interface that allows you to manage and monitor your Kubernetes clusters. It provides an easy-to-use graphical interface where you can view and manage the status of your applications, deploy containerized applications, troubleshoot issues, and manage cluster resources. With the dashboard, you can get insights into your cluster's overall health, view detailed information about your workloads, and access logs to debug and resolve issues. It is a helpful tool for both developers and system administrators to interact with their Kubernetes environment without needing to use the command line.
Other than the features mentioned above you can also you can check the logs and status of the resources which you are using in the kubernetes cluster.
Follow the steps that mentioned below to access the kuebernetes dashboard by the token.
Step 1: First you need to get the token to access the kubernetes dashboard for that using the following command.
kubectl -n kube-system get secret $(kubectl -n kube-system get serviceaccount dashboard -o jsonpath='{.secrets[0].name}')
-o go template='{{.data.token}}'
Step 2: After getting the access token know copy and paste the token in the kubernetes dashboard Dialuge box from where you can access the kubernetes dashboard.
If you want to set up a Kubernetes dashboard for your application then you need to create the following.
In this, the deployment is going to take care of the pod and the service is going to take care to expose the pod to the internet. After deploying the Kubernetes dashboard you can access it from the internet by using localhost (http://localhost:8080.)
Save the below code in any file and execute it
kubectl apply -f (mention file name)
apiVersion: v1
kind: Namespace
metadata:
name: kubernetes-dashboard
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
---
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
ports:
- port: 443
targetPort: 8443
selector:
k8s-app: kubernetes-dashboard
---
apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-certs
namespace: kubernetes-dashboard
type: Opaque
---
apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-csrf
namespace: kubernetes-dashboard
type: Opaque
data:
csrf: ""
---
apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-key-holder
namespace: kubernetes-dashboard
type: Opaque
---
kind: ConfigMap
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-settings
namespace: kubernetes-dashboard
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
rules:
# Allow Dashboard to get, update and delete Dashboard exclusive secrets.
- apiGroups: [""]
resources: ["secrets"]
resourceNames: ["kubernetes-dashboard-key-holder",
"kubernetes-dashboard-certs", "kubernetes-dashboard-csrf"]
verbs: ["get", "update", "delete"]
# Allow Dashboard to get and update
'kubernetes-dashboard-settings' config map.
- apiGroups: [""]
resources: ["configmaps"]
resourceNames: ["kubernetes-dashboard-settings"]
verbs: ["get", "update"]
# Allow Dashboard to get metrics.
- apiGroups: [""]
resources: ["services"]
resourceNames: ["heapster", "dashboard-metrics-scraper"]
verbs: ["proxy"]
- apiGroups: [""]
resources: ["services/proxy"]
resourceNames: ["heapster", "http:heapster:",
"https:heapster:", "dashboard-metrics-scraper",
"http:dashboard-metrics-scraper"]
verbs: ["get"]
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
rules:
# Allow Metrics Scraper to get metrics from the Metrics server
- apiGroups: ["metrics.k8s.io"]
resources: ["pods", "nodes"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: kubernetes-dashboard
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard
namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kubernetes-dashboard
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kubernetes-dashboard
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard
namespace: kubernetes-dashboard
---
kind: Deployment
apiVersion: apps/v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s-app: kubernetes-dashboard
template:
metadata:
labels:
k8s-app: kubernetes-dashboard
spec:
containers:
- name: kubernetes-dashboard
image: kubernetesui/dashboard:v2.4.0
imagePullPolicy: Always
ports:
- containerPort: 8443
protocol: TCP
args:
- --auto-generate-certificates
- --namespace=kubernetes-dashboard
# Uncomment the following line to manually
specify Kubernetes API server Host
# If not specified, Dashboard will attempt
to auto discover the API server and connect
# to it. Uncomment only if the default does not work.
# - --apiserver-host=http://my-address:port
volumeMounts:
- name: kubernetes-dashboard-certs
mountPath: /certs
# Create on-disk volume to store exec logs
- mountPath: /tmp
name: tmp-volume
livenessProbe:
httpGet:
scheme: HTTPS
path: /
port: 8443
initialDelaySeconds: 30
timeoutSeconds: 30
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsUser: 1001
runAsGroup: 2001
volumes:
- name: kubernetes-dashboard-certs
secret:
secretName: kubernetes-dashboard-certs
- name: tmp-volume
emptyDir: {}
serviceAccountName: kubernetes-dashboard
nodeSelector:
"kubernetes.io/os": linux
# Comment the following tolerations if Dashboard must not be deployed on master
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
---
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: dashboard-metrics-scraper
name: dashboard-metrics-scraper
namespace: kubernetes-dashboard
spec:
ports:
- port: 8000
targetPort: 8000
selector:
k8s-app: dashboard-metrics-scraper
---
kind: Deployment
apiVersion: apps/v1
metadata:
labels:
k8s-app: dashboard-metrics-scraper
name: dashboard-metrics-scraper
namespace: kubernetes-dashboard
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s-app: dashboard-metrics-scraper
template:
metadata:
labels:
k8s-app: dashboard-metrics-scraper
spec:
securityContext:
seccompProfile:
type: RuntimeDefault
containers:
- name: dashboard-metrics-scraper
image: kubernetesui/metrics-scraper:v1.0.7
ports:
- containerPort: 8000
protocol: TCP
livenessProbe:
httpGet:
scheme: HTTP
path: /
port: 8000
initialDelaySeconds: 30
timeoutSeconds: 30
volumeMounts:
- mountPath: /tmp
name: tmp-volume
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsUser: 1001
runAsGroup: 2001
serviceAccountName: kubernetes-dashboard
nodeSelector:
"kubernetes.io/os": linux
# Comment the following tolerations if Dashboard must not be deployed on master
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
volumes:
- name: tmp-volume
emptyDir: {}
This will generate the deployment, service, and secret that are required by Kubernetes for the dashboard to function. After executing the command, kubectl creates a namespace, service account, Kubernetes configMap, pods, cluster role, service, RBAC, and deployments resources representing the Kubernetes dashboard.
After executing the command, kubectl creates a namespace, service account, config map, pods, cluster role, service, RBAC, and deployments resources representing the Kubernetes dashboard.
Run the kubectl get command to see if all the resources were successfully installed.
kubectl get all -n Kubernetes-dashboardBy default, the dashboard has restricted access; you'll have to create a service account and connect a cluster role to give it the necessary features.
kubectl create serviceaccount dashboard-admin-saNext, create a cluster role binding that grants the service account the cluster-admin role:
kubectl create cluster role binding dashboard-admin-sa \
--clusterrole=cluster-admin \
--serviceaccount=default:dashboard-admin-sa
Keeping the token used for dashboard authentication secure will prevent the dashboard from doing any action on your cluster.
👁 Creating role bindingExecute the file on the master node using the below command:
kubectl apply -f sa-dashboard.yamlTo log in to the dashboard, you will need the token for the service account you created in Step 2. You can retrieve the token using the following command:
kubectl get sa -n kube-system 👁 Service account kubectl describe sa dashboard-admin -n kube-system👁 Secret kubectl describe secret dashboard-admin-token-v5g7h -n kube-system 👁 Token kubectl proxyThis command will create the proxy servers and you can access the dashboard.
Now that the proxy has been started, you can use your web browser to access the Kubernetes dashboard URL:
http://localhost:8001/api/v1/namespaces/
kubernetes-dashboard/services
/https:kubernetes-dashboard:/proxy/
This URL is for the Kubernetes dashboard login. Enter the token that you receive while login into the dashboard (step 3). Now, the Kubernetes dashboard setup is complete, you can now use it to manage your Kubernetes cluster from GUI.
👁 Kubernetes DashboardFor security reasons, it is recommended that you access the Kubernetes dashboard over a secure connection (HTTPS) rather than HTTP. To set up HTTPS, you will need to create a TLS certificate and configure your Kubernetes API server to use the certificate. You can find more information on how to set up HTTPS for the Kubernetes dashboard in the official Kubernetes.
Deploying the Dashboard in the form of containerized application on kubernetes will give you the flexibility to scale the application with easier way and the availability of the application is also going to increase.
It can be frustrating when you get a "403 Forbidden" error when trying to access the Kubernetes Dashboard. This issue usually indicates you do not have the right sort of liberties to access the dashboard using your user account. Here's an easy instructions for fixing the issue at hand:
kubectl create serviceaccount dashboard-admin -n kube-systemkubectl create clusterrolebinding dashboard-admin-binding \
--clusterrole=cluster-admin \
--serviceaccount=kube-system:dashboard-admin
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep dashboard-admin | awk '{print $1}')