Thursday, December 26, 2024
Google search engine
HomeGuest BlogsInstall Lens – Best Kubernetes Dashboard & IDE

Install Lens – Best Kubernetes Dashboard & IDE

Talking about containers, I believe you know the kind of enthusiasm, uproar, focus and attention that it has earned itself in the past like five years or so. Organizations have been literally shaken, re-organized and others ruminating about the opportunities, the risks and the challenges that this paradigm of handling infrastructure and business applications will bring on the table. For now, developers, DevOps engineers, operations teams and the blue teamers are busy getting as much as they can in order to gauge the viability of this glittering new trend of containerizing applications.

At the heart of this discussion and paradigm shift, sits the famous names such as Kubernetes, Docker, Podman, OpenShift, containerd, CRI-O, Rancher and the likes. You have had a fair share of them and we believe you have burned the midnight oil to get a grasp of what they are all about.

Today, we introduce another name and player in this vast field that goes by the name Lens that has been dubbed “The Kubernetes IDE “. It has grown in popularity due to its features that has made managing Kubernetes friendly. So what is this Lens?

To keep it simple, Lens is a standalone application for MacOS, Windows and Linux operating systems that helps people have a deeper, better and beautiful look and insight into their Kubernetes clusters. It is the most powerful IDE for people who need to deal with Kubernetes clusters on a daily basis. It helps one ensure that their clusters are properly setup and configured, increase their visibility, get real time statistics, log streams and hands-on troubleshooting capabilities. With Lens, you can work with your clusters more easily and fast, radically improving productivity and the speed of business. The best thing about it is that it is open source and free. And guess what, you can contribute to the this noble project and be part of its beauty.

Features of Lens

Apart from what we have already talked about Lens, here are additional features that it boasts of:

  • Multi Cluster Management: Access and work with your clusters with a confidence from a single unified IDE. Lens works with any number of Kubernetes clusters.
  • Built-In Prometheus Stats: See all relevant graphs and resource utilization charts integrated as part of the dashboard. Lens comes with a built-in and multi-tenant Prometheus setup that will respect RBAC for each user.
  • Context Aware Terminal: The built-in terminal comes with kubectl that is always API compatible with your cluster and in the right context. Lens built-in terminal will ensure the version of Kubernetes cluster API is compatible with the version of kubectl.
  • Multiple Workspaces: Organize clusters into logical groups. Workspaces are used to organize a number of clusters into logical groups.

To test and see the capabilities of Lens, we will install k3s on a Linux virtual machine and then connect Lens to it to view metrics and monitor how it is faring. K3s is a highly available, certified Kubernetes distribution designed for production workloads in unattended, resource-constrained, remote locations or inside IoT appliances. To start off, let us install k3s on Linux.

Install k3s on Linux (Optional – if you don’t have Kubernetes Cluster)

Run the command below to get k3s downloaded and installed:

$ curl -sfL https://get.k3s.io | sudo sh -
[INFO]  Finding release for channel stable
[INFO]  Using v1.27.4+k3s1 as release
[INFO]  Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.27.4+k3s1/sha256sum-amd64.txt
[INFO]  Downloading binary https://github.com/k3s-io/k3s/releases/download/v1.27.4+k3s1/k3s
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
[INFO]  Skipping installation of SELinux RPM
[INFO]  Skipping /usr/local/bin/kubectl symlink to k3s, command exists in PATH at /usr/bin/kubectl
[INFO]  Skipping /usr/local/bin/crictl symlink to k3s, command exists in PATH at /usr/bin/crictl
[INFO]  Skipping /usr/local/bin/ctr symlink to k3s, command exists in PATH at /usr/bin/ctr
[INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
[INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
[INFO]  systemd: Enabling k3s unit
Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service → /etc/systemd/system/k3s.service.
# Warning: iptables-legacy tables present, use iptables-legacy-save to see them
# Warning: ip6tables-legacy tables present, use ip6tables-legacy-save to see them
[INFO]  systemd: Starting k3s

Check if the node(s) are okay

$ sudo k3s kubectl get node
NAME        STATUS   ROLES    AGE   VERSION
localhost   Ready    master   20m   v1.27.4+k3s1

Looking at that, it means we are good to now proceed to Lens. Let us install Lens.

More about K3s can be found at K3s main page and you can extend it to other nodes by following our detailed Deploy Lightweight Kubernetes Cluster in 5 minutes with K3s guide.

Other Kubernetes Installation guides:

Installation of Lens Kubernetes Dashboard & IDE

To install Lens, you can either download a pre-built package from the releases page or you can be also install it via snapcraft (Linux only). I am on Manjaro and will use the snapcraft way. If you are on windows, visit the link above and download the windows version and since it is already pre-built, it is pretty easy to install.

Enable snapd

### Arch Linux / Manjaro ###
sudo pacman -S snapd

### Ubuntu / Debian ###
sudo apt update
sudo apt install snapd

### CentOS ###
sudo yum install epel-release
sudo yum install snapd

Once installed, the systemd unit that manages the main snap communication socket needs to be enabled as folows:

sudo systemctl enable --now snapd.socket

To enable classic snap support, enter the following to create a symbolic link between /var/lib/snapd/snap and /snap:

sudo ln -s /var/lib/snapd/snap /snap

Reboot your machine to ensure all paths are updated accordingly.

Once your pc is back up install Lens by simply running the following command:

sudo snap install kontena-lens --classic

If you are on on Mac, the following command is enough to get Lens installed.

brew cask install lens

You can now start Lens like other graphical applications.

Kubernetes Cluster Access with Lens

By default, lens looks for ~/.kube/config file which contains information on how it will connect to a Kubernetes cluster. In our server where K3s is installed, the kubeconfig file stored at /etc/rancher/k3s/k3s.yaml is used to configure access to the Kubernetes cluster.

To access the Cluster from Lens which is installed on your personal computer (Linux, Windows or macOS), copy /etc/rancher/k3s/k3s.yaml on your machine located outside the cluster as ~/.kube/config. So I fetched /etc/rancher/k3s/k3s.yaml from the server, created .kube directory and copied the file into it and renamed it to config.

On server

sudo cp /etc/rancher/k3s/k3s.yaml /home/tech
sudo chown tech:tech /home/tech/k3s.yaml

On your local computer

cd ~
mkdir .kube
cd ~/.kube

# For k3s
mv k3s.yaml config

# For other Kubernetes clusters
cp kubeconfig ~/.kube/config

Then I replaced “localhost” with the IP or name of the K3s server. The contents of the file looks like below:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJWekNCL3FBREFnRUNBZ0VBTUFvR0NDcUdTTTQ5QkFNQ01DTXhJVEFmQmdOVkJBTU1HR3N6Y3kxelpYSjIKWlhJdFkyRkFNVFU1T0RZek56Y3dOakFlRncweU1EQTRNamd4T0RBeE5EWmFGdzB6TURBNE1qWXhPREF4TkRaYQpNQ014SVRBZkJnTlZCQU1NR0dzemN5MXpaWEoyWlhJdFkyRkFNVFU1T0RZek56Y3dOakJaTUJNR0J5cUdTTTQ5CkFnRUdDQ3FHU000OUF3RUhBMElBQkdDVXY2WHRoQ2lGRVQySEowNm5ac1d5aFN4UTBvNmZ4NlBhNGJnc21qcmQKNUZzcThvNUt0UEUrTW92UjRhNERIdy9aZDh1TkNlSmNRb2lVRXByYms4V2pJekFoTUE0R0ExVWREd0VCL3dRRQpBd0lDcERBUEJnTlZIUk1CQWY4RUJUQURBUUgvTUFvR0NDcUdTTTQ5QkFNQ0EwZ0FNRVVDSUdaSTBNU3hteXN6ClppbFYwQWY2RzB6Ri8zOW1LWEdQTytYQ3VxK2E2L1FEQWlFQXFtbU93WFlXbWtPVGZONEF3eUg1ZjRaVDR1ZVkKY1dwVFVxQmtSdWMrM1RJPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
    server: https://192.168.121.108:6443
  name: default
contexts:
- context:
    cluster: default
    user: default
  name: default
current-context: default
kind: Config
preferences: {}
users:
- name: default
  user:
    password: 1f9472d132670bd38c14c44ae7c8b415
    username: admin

Change server: https://192.168.121.108:6443 to point to the server where K3s is installed. Make sure port 6443 is accessible from outside as well.

Launching and Using Lens to Manage Kubernetes Resources

Once all of your configs are looking good, it is time to launch lens and attempt to connect to our K3s cluster. The first page should look like below. Click on the + sign to add a cluster.

Lens page 1

A page similar to the one illustrated below will be presented. On the drop-down labelled Kubeconfig, click on the arrow and you should see default automatically discovered.

Lens page 2 add cluster
Lens page s add default config

If it is not discovered by default, choose Custom and paste the contents similar to the one shown above on the text area that will be presented below it. Once done, click on “Add Cluster“. If all goes well, your cluster details will appear as shown below.

Lens page 4 cluster dashboard 1

In case you see the message “Metrics are not available due to missing or invalid Prometheus configuration…” simply right click cluster icon (big +) and click on “settings“.

Lens page 5 click settings 1

Once there, install metrics and choose Lens as the Prometheus installation method. That will deploy a prometheus pod to handle metrics.

Lens page 6 install metrics feature and choose lens

The dashboard should be populated with pretty statistics and graphs after some few seconds.

Lens page 7 metric available

View Nodes

To view your nodes, simply click on your cluster and hit on the “Nodes” Menu provided.

Lens nodes

View Workload

The workloads tab has sub-menu items such as as Pods, Deployments, DaemonSets and others as you can view from the interface.

Lens workload overview

View Network Resources

Similarly, under “Network” tab, you will view the Endpoints, Ingresses and Network Services exhibited. Every configured service will be visible herein as well.

Lens network services

View Pods and their Logs

Being able to view pods’ logs without logging into the terminal of your cluster makes Lens stand out. Simply click on “Pods” which is under “Workloads.” From there, you should see all of your pods and on the far right of each pod, there are 3 vertical dots. Clicking on each pops out other menu items including “Logs, shell, Edit and delete.”

Lens workload pod choose logs shell

Access Node Shell

From Lens interface, you can access node’s shell conveniently. Click on “Nodes” and on the far right of each of your nodes, click on the three vertical dots and choose shell. A terminal should be opened as shown below where you can issue urgent commands without leaving Lens.

Lens open node terminal

Last Remarks

As we have already highlighted, Lens is a standalone application for MacOS, Windows and Linux operating systems. It is like any other application in your favorite Operating System. It can run on your Laptop or PC and then connects to your Kubernetes cluster for visibility, real time statistics, log streams and hands-on troubleshooting as we have briefly seen. As usual, this guide is not exhaustive because Lens offers much more. Other details about Lens can be found at Lens Kubernetes IDE main webpage.

To conclude, we continue to appreciate your support and we hope this guide was helpful. Check below for much more.

RELATED ARTICLES

Most Popular

Recent Comments