Kubernetes (sometimes shortened to K8s with the 8 standing for the number of letters between the “K” and the “s”) is an open-source system to deploy, scale, and manage containerized applications anywhere. Kubernetes is a container-centric management software that allows the creation and deployment of containerized applications with ease. Originally created by Google Cloud in 2014, Kubernetes is now being offered by leading Cloud Providers like AWS and Azure. Kubernetes offers a dashboard (Web User Interface) to monitor all the workflows running in the cluster. Using the dashboard, we can monitor the usage, and the stress of clusters as well as basic resource usage and logs of the services running in the clusters. A Certified Kubernetes Administrator / CKA Course is the best way to learn the deployment of the Kubernetes dashboard.
What is the Kubernetes Dashboard?
Kubernetes Dashboard is a general-purpose, web-based UI for Kubernetes clusters. It allows users to manage applications running in the cluster and troubleshoot them, as well as manage the cluster itself.
As in the image, the Kubernetes UI offers a variety of services like scheduling cron jobs, shows the current usage of nodes and pods present in the cluster. All the settings can be configured using the dashboard itself.
Deploying the Dashboard UI
Direct Method:
To deploy the dashboard in the Kubernetes cluster. Please follow the below steps.
- Execute following command: kubectl apply -f
- To access Dashboard from your local workstation you must create a secure channel to your Kubernetes cluster. Run the following command :kubectl proxy
To access the Kubernetes dashboard open this on your browser - http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/.
You should now see the Kubernetes dashboard deployed during cluster creation.
using Helm
Alternatively, Kubernetes dashboard can also be installed using Helm
To install the Chart with the Release name kubernetes-dashboard:
helm repo add kubernetes-dashboard
helm install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard
The following command deploys the Kubernetes dashboard in the default setting. We can also change configurations like the following command.
helm install kubernetes-dashboard/kubernetes-dashboard --name kubernetes-dashboard \
--set=service.externalPort=8080,resources.limits.cpu=200m
Specify each parameter using the --set key=value[,key=value] argument to helm install
Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example,
helm install kubernetes-dashboard/kubernetes-dashboard --name kubernetes-dashboard -f values.yaml
Uninstalling the Chart on Helm
We can also uninstall the Kubernetes dashboard using helm charts. The following command uninstalls the helm chart for Kubernetes dashboard.
helm delete kubernetes-dashboard
It deletes the entire Kubernetes components and their releases.
Accessing the Dashboard UI
It is possible to access the Kubernetes UI using Authentication Token(RBAC). We will have to create a new user account using the service account mechanism of Kubernetes, grant the user admin permissions and login into the dashboard using the bearer token tied to the user. The tokens differ for each user.
We can now look at the steps of creating a new user in Kubernetes:
1. Create a Service Account with any name in the namespace Kubernetes-dashboard first. I have attached a sample YAML file.
apiVersion: v1
kind: ServiceAccount
metadata:
name: user
namespace: kubernetes-dashboard
2. Create a ClusterRoleBinding
If you are using kops, kubeadm or any other popular tool, the ClusterRole cluster-admin already exists in the cluster. We can use it and create only a ClusterRoleBinding for our ServiceAccount. If it does not exist then you need to create this role first and grant required privileges manually.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
3. Generate a bearer token:
Execute the following command:
kubectl -n kubernetes-dashboard create token admin
It should print something like:eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXY1N253Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIwMzAzMjQzYy00MDQwLTRhNTgtOGE0Ny04NDllZTliYTc5YzEiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlcy1kYXNoYm9hcmQ6YWRtaW4tdXNlciJ9.Z2JrQlitASVwWbc-s6deLRFVk5DWD3P_vjUFXsqVSY10pbjFLG4njoZwh8p3tLxnX_VBsr7_6bwxhWSYChp9hwxznemD5x5HLtjb16kI9Z7yFWLtohzkTwuFbqmQaMoget_nYcQBUC5fDmBHRfFvNKePh_vSSb2h_aYXa8GV5AcfPQpY7r461itme1EXHQJqv-SN-zUnguDguCTjD80pFZ_CmnSE1z9QdMHPB8hoB4V68gtswR1VLa6mSYdgPwCHauuOobojALSaMc3RH7MmFUumAgguhqAkX3Omqd3rJbYOMRuMjhANqd08piDC3aIabINX6gP5-Tuuw2svnV6NYQ
Copy the token and paste it into the Enter token field on the login screen.
Click on the sign in button and you will be able to access the dashboard.
Kubernetes Dashboard Overview and Basic Operations
Let's look at the basic elements that can be monitored using the Kubernetes Dashboard.
There are two segments by which we can monitor the usage of resources.
- Cluster Level
- Workloads Level
Cluster Level
This segment can be used to monitor the metrics from a cluster level. Basically, we can monitor Cluster Roles, Namespaces, Nodes, Persistent Volumes and Storage classes.
All the metrics are calculated on a cluster level only.
Workloads Level
The workloads level shows details on applications that are running in Kubernetes Cluster like Cron jobs that are scheduled, Daemon sets, deployments, jobs and pods usage with time.
The workloads level can be used to monitor the pods closely and increase or decrease the configurations (Hardware) of pods if necessary to avoid high costs or sudden overload.
Namespace Level
The Kubernetes dashboard also offers to monitor the resources on a namespace level. This gives a real insight into how much resource utilization is happening on a namespace level. If needed we can create extra pods if the consumption is too high or we can shift pods into a different namespace depending on the utilization.
We have a complete course on DevOps, to learn more about technologies used in DevOps.
Deploying Containerized Applications
With the help of the Kubernetes dashboard, we can directly deploy the containerized applications without using the Command Line Interface.
You can either manually specify application details, or upload a YAML or JSON manifest file containing application configuration.
- Step 1: Click on the Create button on top left of the Welcome Page.
- Step 2: You are required to fill the configurations of the applications.
- App Name- Name for your Application
- Container Image - The URL of the Docker image from the private registry or from dockerhub if its public
- Number of Pods - The number of pods required(Based on the requirement)
- Service - This is an optional field. If you want to expose some parts of your application for external services. You can specify it here.
- Step 3: Advanced Configurations.
Description: Description of the application that you are going to deploy
Labels- Labels can be additional information about the application’s deployment for example (
release=1.0
tier=frontend
environment=pod
track=stable
)
- Namespace- Namespaces are virtual cluster which lets you partition the cluster into logical groups.
- Image pull secret - If the specified Docker image is private, it would need the image pull secrets.
- CPU requirement : You can specify the minimum resource limits for the container.
- Run command and Run command arguments: You can use the command options and arguments to override the starting point of the docker container
- Run as privileged: This setting can be used to set the privileges for the container
- Environment variables: It is also possible to pass environment variables from the dashboard using this config
Uploading a YAML or JSON file
As an alternative, all the configurations can also be mentioned in the form of YAML or JSON and can be uploaded to the cluster using the dashboard UI.
Using Dashboard
The following sections describe various sections present in the Kubernetes dashboard UI.
Admin overview
This section depicts the overall cluster and node information. It gives an overview from a higher level of consumption of resources, services and pods.
Workloads
It shows all the applications running in a particular namespace. This view goes into much detail like Deployments, ReplicaSets and StatefulSets. Each Workload can be viewed separately.
Services
This section lists all the services that are exposed from the Kubernetes cluster for internal bindings.
Storage
This section lists all the StorageVolumeclaim used by the Kubernetes resources for storing data within the Kubernetes cluster.
ConfigMaps and Secrets
This section shows all the live configs that are actively used by the Kubernetes cluster. It also shows the environment variables(secrets) defined in the Kubernetes cluster.
Logs viewer
As the name suggests, this section is used to view logs on a pod level as well as on a cluster level.
Conclusion
In this blog, we have discussed how to set up Kubernetes Dashboard using CLI as well as using helm charts. We discussed the various functionalities as well as the sections that the dashboard offers. The dashboard can also be used to directly deploy containers in Kubernetes. You can also refer to these links to learn more about K8s and K8s dashboard. Check out the Best Course for Docker and Kubernetes offered by KnowledgeHut.
Additional Resources
- https://github.com/kubernetes/dashboard
- https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/
- https://docs.aws.amazon.com/eks/latest/userguide/dashboard-tutorial.html
- https://artifacthub.io/packages/helm/k8s-dashboard/kubernetes-dashboard