What is Lens and why use it?
Lens is an open-source IDE for Kubernetes that makes it easier to manage our Kubernetes cluster whether running on a local host or on any cloud provider through a graphical interface instead of CLIs through which it gets a little complex when modifying or creating a new resource, Though we can use Kubectl (k8s CLI) in the terminal that is provided by the Lens.
Installation and Setup
Download the desktop version of Lens from its official site. Make sure to select the OS you are currently on before downloading the setup.
How does Lens knows where clusters are running?
While browsing the catalog in the lens, when you click on the cluster tab, you could see that there is only one cluster running on my local machine i.e Minikube (Minikube allows you to run only 1 node on your local host, The control plane and the worker node both act as one node only in your cluster). Now if you look closely under the labels section, there is a Kube-config file.
This file holds information regarding the Kubernetes cluster, certificate, unique token to authenticate the cluster, and all the info on how this cluster will be connected with the Lens. This Kube-config file is present in the home directory of the cluster.
Connecting your cluster with Lens
Currently, you could not see any insights about my Minikube cluster as shown in the previous image because it's not yet connected to the Lens. To connect it, simply click on the cluster. You will see something like this as shown in the image below...
If by any chance you are still not able to see metrics, then make sure to follow these steps first:
- Open the cluster settings and inside the metrics tabs, set Lens as query format to fetch data from Prometheus (It's a free software application used for event monitoring and alerting.)
- Then head over to the extensions section on the same page, and inside Lens Metrics tab, Enable those all 3 features and click on apply:
After these changes and once Lens is connected, It will provide you with lots and lots of information about your cluster, you could now easily take a better look at your workloads (Kubernetes objects that are running inside your cluster like pods, deployments, etc), you can check config maps( an API object used to store non-confidential data in key-value pairs) under Config tab, can check Networks, Storage and more:
Adding your cluster to Lens
We can add clusters to Lens by pressing Ctrl+Shift+A
keys together, then it will ask you to paste your Kube-config file, which you can find in the home directory as mentioned before. Once you've pasted your config file, then simply click on add cluster.
Creating a resource
You can simply hover over the "+" icon next to the terminal and then click on the "create resource" button. After that you will have to choose which resource you will create, So let's try creating a Pod (An functional scheduling unit) by selecting your template as a Pod.
Now if you head over to the Workload section and then to Pods, you could see your pod running there...
This way, you have just avoided the approach where you had to create this pod through Kubectl, where you have to manually set up a YAML file and make changes in it through CLI in the terminal, which could get complex and challenging when working with multiple k8s objects.