Kubernetes dashboard is a web-based user interface which provides information on the state of the Kubernetes cluster resources and any errors that may occur. The dashboard can be used to deploy containerized applications to the cluster, troubleshoot deployed applications, as well as the general management of the cluster resources.
The deployment of Deployments, StatefulSets, DaemonSets, Jobs, Services and Ingress can be done from the dashboard or from the terminal with kubectl. if you want to scale a Deployment, initiate a rolling update, restart a pod, create a persistent volume and persistent volume claim, you can do all from the Kubernetes dashboard.
Step 1: Configure kubectl
We’ll use the kubectl kubernetes management tool to deploy dashboard to the Kubernetes cluster. You can configure kubectl using our guide below.
Easily Manage Multiple Kubernetes Clusters with kubectl & kubectx
The guide in the link demonstrates how you can configure and access multiple clusters with same kubectl configuration file.
Step 2: Deploy Kubernetes Dashboard
The default Dashboard deployment contains a minimal set of RBAC privileges needed to run. You can deploy Kubernetes dashboard with the command below.
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended.yaml
This will use the default values for the deployment. If you want to make some modifications to the file, you’ll have to download it to your local machine.
wget https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended.yaml
mv recommended.yaml kubernetes-dashboard-deployment.yml
Modify the file to fit your deployment needs.
vim kubernetes-dashboard-deployment.yml
I’ll modify the Kubernetes dashboard service to be of NodePort type.
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
type: NodePort
- NodePort exposes the Service on each Node’s IP at a static port (the NodePort). A ClusterIP Service, to which the NodePort Service routes, is automatically created.
Apply the changes when done:
kubectl apply -f kubernetes-dashboard-deployment.yml
Check deployment status:
$ kubectl get deployments -n kubernetes-dashboard
NAME READY UP-TO-DATE AVAILABLE AGE
dashboard-metrics-scraper 1/1 1 1 86s
kubernetes-dashboard 1/1 1 1 86s
Two pods should be created – One for dashboard and another for metrics.
$ kubectl get pods -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
dashboard-metrics-scraper-7b64584c5c-xvtqp 1/1 Running 0 2m4s
kubernetes-dashboard-566f567dc7-w59rn 1/1 Running 0 2m4s
Since I changed service type to NodePort, let’s confirm if the service was actually created.
$ kubectl get service -n kubernetes-dashboard
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dashboard-metrics-scraper ClusterIP 10.43.133.26 8000/TCP 2m59s
kubernetes-dashboard NodePort 10.43.150.245 443:30038/TCP 3m
Step 3: Accessing Kubernetes Dashboard
My Service deployment was assigned a port 30038/TCP. Let’s confirm if access to the dashboard is working.
You need a token to access the dashboard, check our guides:
How To Create Admin User to Access Kubernetes Dashboard
Create Kubernetes Service / User Account restricted to one Namespace
You should see a web dashboard which looks similar to below.
Nginx Ingress:
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: k8s-dashboard
namespace: kubernetes-dashboard
annotations:
nginx.ingress.kubernetes.io/secure-backends: "true"
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
spec:
tls:
- hosts:
- k8sdash.mydomain.com
secretName: tls-secret
rules:
- host: k8sdash.mydomain.com
http:
paths:
- path: /
backend:
serviceName: kubernetes-dashboard
servicePort: 443
Check other Kubernetes guides:
Top Minimal Container Operating Systems for running Kubernetes
Install Production Kubernetes Cluster with Rancher RKE
Install Minikube Kubernetes on CentOS 8 / CentOS 7 with KVM
How To Schedule Pods on Kubernetes Control plane (Master) Nodes