Managing a Kubernetes cluster can be a daunting task for many reasons. Kubernetes is a complex system that requires knowledge of multiple components, including pods,services, deployments, replicasets, and more. Moreover, managing a Kubernetes cluster using CLI requires an in-depth understanding of Kubernetes resource specifications, such as YAML files, and the intricacies of Kubernetes API.

………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………

Managing a Kubernetes cluster can be a daunting task for many reasons. Kubernetes is a complex system that requires knowledge of multiple components, including pods, services, deployments, replicasets, and more. Moreover, managing a Kubernetes cluster using CLI requires an in-depth understanding of Kubernetes resource specifications, such as YAML files, and the intricacies of Kubernetes API.

The CLI tools that come with Kubernetes, such as kubectl, provide a comprehensive set of commands to manage a Kubernetes cluster. However, managing a large-scale Kubernetes cluster using these tools can be difficult, as it requires typing complex commands repeatedly, which can lead to errors and typos.

Another challenge with managing a Kubernetes cluster using CLI is the lack of visibility into the resources and their state in the cluster. CLI tools provide information about the resources, but the output is often difficult to parse and comprehend, making it challenging to troubleshoot and debug issues.

Finally, Kubernetes is a dynamic system that changes frequently, with new resources being created and deleted continuously. Managing a Kubernetes cluster using CLI requires constantly monitoring the state of the cluster and making changes as necessary. This can be a time-consuming and error-prone task, especially when managing a large-scale cluster with multiple nodes and resources.

Overall, managing a Kubernetes cluster using CLI can be challenging due to the complexity of the system, the difficulty in managing large-scale clusters, and the lack of visibility into the state of resources in the cluster.

Introduction to K9s

K9s is a terminal-based user interface (UI) tool that simplifies the management of Kubernetes clusters. K9s provides real-time tracking of activities of resources running in the Kubernetes cluster, supports both standard Kubernetes resources as well as custom resource definitions (CRDs), and tracks real-time metrics associated with resources such as pods, containers, and nodes.

K9s provides a powerful filtering mode to allow users to drill down and view workload-related resources, and it also supports error zoom, which allows users to drill down directly to what’s wrong with their cluster’s resources. K9s also provides plugin support to extend K9s to create custom cluster commands, and it supports command shortcuts for quick navigation via command aliases and hotkeys.

Overall, K9s simplifies Kubernetes cluster management by providing an intuitive and easy-to-use UI that tracks real-time activities and metrics.

Kubernetes Cluster management Made Easy with K9s

Image21

K9s simplifies Kubernetes cluster management by providing a user-friendly UI that tracks real-time activities and metrics. K9s provides a powerful filtering mode that allows users to drill down and view workload-related resources. This makes it easy for users to identify any issues with their applications and take necessary actions to resolve them.

K9s also supports error zoom, which allows users to drill down directly to what’s wrong with their cluster’s resources. This feature simplifies the troubleshooting process and helps users to quickly identify and fix any issues.

K9s also provides plugin support to extend K9s to create custom cluster commands, and it supports command shortcuts for quick navigation via command aliases and hotkeys. This makes it easy for users to perform common tasks such as logs, scaling, port-forwards, restarts, etc.

Overall, K9s simplifies Kubernetes cluster management by providing an intuitive and easy-to-use UI that tracks real-time activities and metrics.

Compelling Features of K9s

K9s provides a wide range of features that make it easier to manage Kubernetes clusters. Some of its key features include:

  • Real-time monitoring: K9s provides real-time monitoring of resources running in a Kubernetes cluster, including detailed metrics and logs.
  • Customization: K9s can be customized to suit the needs of individual users, including custom skins, command shortcuts, and column displays.
  • Filtering: K9s provides powerful filtering options that allow users to drill down and view specific resources based on a variety of criteria.
  • Port forwarding: K9s supports port forwarding, making it easier to access and test Kubernetes services.

Image7

  • Benchmarking: K9s includes a built-in benchmarking tool that allows users to benchmark HTTP endpoints and adjust resource requests and limits accordingly.
  • RBAC support: K9s supports Role-Based Access Control (RBAC) and provides RBAC rule viewing capabilities.

Installation Steps for K9s

K9s can be installed on various platforms, including macOS, Linux, and Windows. Here are the steps to install K9s on Linux:

1) Download the latest K9s binary from the official GitHub release page:

wget https://github.com/derailed/k9s/releases/latest/download/k9s_Linux_x86_64.tar.gz

2) Extract the downloaded binary using the following command:

tar -xzvf k9s_Linux_x86_64.tar.gz

3) Move the extracted binary to the /usr/local/bin directory to make it globally accessible:

sudo mv k9s /usr/local/bin/

Now, K9s is installed on your Linux machine, and you can start using it.

Command Examples snippets of K9s

Here are some examples of the K9s command-line tool:

a) View all resources in the Kubernetes cluster:

k9s

This command will open the K9s terminal user interface, showing all the available resources in your Kubernetes cluster.

b) View the details of a specific resource:

k9s <resource-name>

Replace with the name of the resource you want to view. For example, k9s pods will show you all the available pods in the cluster.

c) View the logs of a pod:

k9s logs <pod-name>

Image41

Replace with the name of the pod whose logs you want to view.

d) View the metrics of a pod:

k9s metrics pod <pod-name>

This command will show you the CPU and memory usage of the specified pod.

e) Scale a deployment:

k9s scale deploy <deployment-name> --replicas=<number>

Image51

Replace with the name of the deployment you want to scale and with the number of replicas you want to set.

f) Forward a local port to a pod:

k9s port-forward <pod-name> <local-port>:<pod-port>

Replace with the name of the pod, with the local port number, and with the pod port number. This command will forward the specified pod port to the specified local port.

Image7

g) Benchmark a Kubernetes service:

k9s benchmark service <service-name> --concurrency=<number> --requests=<number> --verb=<http-verb> --path=<http-path>

Replace with the name of the Kubernetes service you want to benchmark, with the desired concurrency and number of requests, with the HTTP verb to use, and with the HTTP path to request.

These are just some examples of the many commands and options available in K9s. With its intuitive user interface and powerful features, K9s makes managing a Kubernetes cluster much easier and efficient.

Here are some detailed examples of commonly used K9s commands:

Viewing Resources

  • To view all the pods in the default namespace, simply type pods or po and press enter. This will bring up a list of all pods in the default namespace.
  • To view all the services in the default namespace, type services or svc.

Image23

  • To view all the deployments in the default namespace, type deployments or deploy.
  • To view all the nodes in the cluster, type nodes.

Filtering Resources

K9s has a powerful filtering mode to allow users to drill down and view workload related resources. To enter filter mode, type / and then enter the filter criteria. For example, to view all the pods that have a label app=web, type /app=web and press enter.

To clear the filter and exit filter mode, simply press the Esc key.

Viewing Resource Details

  • To view the details of a specific resource, select the resource in the list view and press enter. This will bring up a detailed view of the resource, including metadata, labels, and annotations.
  • To view the logs of a specific pod, select the pod in the list view and press l. This will bring up a real-time view of the pod’s logs.

Managing Resources

  • To delete a resource, select the resource in the list view and press d. This will prompt you to confirm the deletion before proceeding.

Image5

  • To edit the configuration of a resource, select the resource in the list view and press e. This will bring up an editor where you can modify the resource configuration.

Port Forwarding

To set up a port-forward, navigate to the PodView, select a pod and a container that exposes a given port. Using SHIFT-F, a dialog comes up to allow you to specify a local port to forward to.

Once acknowledged, you can navigate to the PortForward view (alias pf) listing out your active port-forwards. Selecting a port-forward and using CTRL-B will run a benchmark on that HTTP endpoint.

Benchmarking Resources

To benchmark a resource, set up a port-forward as described above and navigate to the Benchmarks view (alias be). Select the benchmark you want to run and press CTRL-B. This will run a benchmark on the HTTP endpoint and display the results in real-time.

Customizing K9s

K9s is highly customizable, allowing users to define their own command shortcuts, hotkeys, and skins. To customize K9s, navigate to the ~/.k9s directory and edit the config.yml file. Here, you can define your own command aliases and hotkeys, as well as modify the look and feel of K9s using skins.

RBAC Management

On RBAC enabled clusters, you would need to give your users/groups capabilities so that they can use K9s to explore their Kubernetes cluster. K9s needs minimally read privileges at both the cluster and namespace level to display resources and metrics.

You can customize RBAC rules based on your environment policies. For example, to give a user read access to a specific namespace, you can create a role with read permissions and bind it to the user or group using a role binding.

These are just a few examples of the many commands and features available in K9s. By using K9s, you can simplify your Kubernetes cluster management and streamline your workflows.

How K9s is used for Benchmarking Kubernetes Cluster with an Example

  • K9s integrates Hey, a CLI tool to benchmark HTTP endpoints similar to AB bench. This feature currently supports benchmarking port-forwards and services. Here’s how you can use K9s for benchmarking a Kubernetes cluster:
  • Navigate to the PodView in K9s and select a pod and a container that exposes a given port.
  • Use SHIFT-F to open a dialog box and specify a local port to forward to.
  • Navigate to the PortForward view (alias pf) to list out your active port-forwards.
  • Select a port-forward and use CTRL-B to run a benchmark on that HTTP endpoint.
  • To view the results of your benchmark runs, go to the Benchmarks view (alias be). You can select a benchmark and view the run stats details by pressing . Initially, the benchmarks will run with the following defaults:
Concurrency Level: 1
Number of Requests: 200
HTTP Verb: GET
Path: /

K9s also provides a benchmark configuration file, namely: $XDG_CONFIG_HOME/k9s/bench-.yml. Each cluster you connect to will have its own bench config file. Changes to this file should automatically update the PortForward view to indicate how you want to run your benchmarks.

How K9s helps even in managing RBAC Kubernetes Cluster

On RBAC enabled clusters, you need to give your users/groups capabilities so that they can use K9s to explore their Kubernetes cluster. K9s needs minimally read privileges at both the cluster and namespace level to display resources and metrics. The following are some suggested rules:

Cluster Role:
apiVersion: rbac.authorization.k8s.io/v1 
kind: ClusterRole 
metadata: 
name: k9s-read-only 
rules: 
- apiGroups: ["*"] 
  resources: ["*"] 
  verbs: ["get", "watch", "list"] 
- nonResourceURLs: ["/metrics"] 
  verbs: ["get"]
Cluster Role Binding:
apiVersion: rbac.authorization.k8s.io/v1 
kind: ClusterRoleBinding 
metadata: 
name: k9s-read-only 
subjects: 
- kind: Group 
  name: k9s-users 
  apiGroup: rbac.authorization.k8s.io 
  roleRef: 
  kind: ClusterRole 
  name: k9s-read-only 
  apiGroup: rbac.authorization.k8s.io

These rules are just suggestions, and you will need to customize them based on your environment policies. If you need to edit or delete resources, extra permissions will be necessary.

Conclusion

Managing a Kubernetes cluster can be a tough job, but K9s can make it easier. K9s is a terminal-based UI tool that allows you to navigate, observe, and manage your Kubernetes clusters with ease. Its features include real-time tracking of resource activities, support for both standard and custom resources, cluster metrics, powerful filtering modes, and more.
Installing K9s is easy, and once you have it up and running, you can start exploring your Kubernetes cluster right away. K9s also supports benchmarking of your cluster using Hey and helps with managing RBAC enabled clusters by providing suggested rules for read-only access.

In summary, K9s is an excellent tool for anyone managing Kubernetes clusters, and its user-friendly interface and powerful features make it a must-have tool for DevOps and Kubernetes administrators.

Leave a Reply

Your email address will not be published. Required fields are marked *

Take your startup to the next level