☁️How to Install k9s and kubectl — Testing on Huawei CCE

Rabia Yılmaz
Huawei Developers
Published in
8 min readSep 25, 2023
Kubernetes Kubectl

Introduction

👋 Hello! I'd be happy to provide you with an introduction to installing k9s and kubectl, two essential tools for managing Kubernetes clusters efficiently. Let's get started! 🚀

What is kubectl?

Kubectl is the official command-line tool used for interacting with Kubernetes clusters. It serves as the primary interface for managing and controlling Kubernetes resources and performing various operations within a cluster. Developed by the Kubernetes community, kubectl simplifies the management of containerized applications and the underlying infrastructure.

Here are some key features and functions of kubectl:

🔹 Cluster Communication: kubectl allows users to communicate with Kubernetes clusters. It provides a unified interface to access and control the cluster resources, regardless of the underlying infrastructure or provider.

🔹 Resource Management: With kubectl, you can create, read, update, and delete Kubernetes resources. These resources include pods, deployments, services, replica sets, config maps, secrets, and more. kubectl enables you to manage the lifecycle of these resources, scaling them up or down, rolling out updates, and monitoring their status.

🔹 Cluster Administration: kubectl provides functionalities for administering Kubernetes clusters. You can retrieve cluster information, manage namespaces, view and modify cluster-level settings, perform troubleshooting tasks, and inspect different cluster components.

🔹 Interacting with Kubernetes API: kubectl acts as a client to the Kubernetes API server. It simplifies the process of making API requests to the cluster and handling authentication, authorization, and communication protocols on behalf of the user.

🔹 Control and Monitoring: kubectl offers control and monitoring capabilities for Kubernetes clusters. You can check the status of your resources, retrieve logs, perform pod port-forwarding for local access, execute commands within containers, and collect diagnostic information.

🔹 Extensibility: kubectl supports plugins, allowing users to extend its functionality and add custom commands. Plugin integration enables third-party tools and utilities to integrate seamlessly with kubectl, enhancing its capabilities.

To use kubectl effectively, it's crucial to understand its commands, options, and YAML-based configurations. The Kubernetes documentation provides comprehensive guidance on kubectl and its usage, including command references, tutorials, and best practices.

What is K9s?

K9s is a command-line interface (CLI) tool designed to provide a more intuitive and interactive experience for managing Kubernetes clusters. It serves as an alternative to using the standard `kubectl` command.

Here are some key features of k9s:

🔹 Efficient Resource Navigation: k9s simplifies the navigation and exploration of Kubernetes resources. It provides a comprehensive and dynamic view of your cluster's resources, allowing you to browse and search for specific resources quickly.

🔹 Interactive UI: k9s offers an intuitive and user-friendly terminal-based UI. It presents resource details in a clear and structured format, making it easier to understand and work with complex Kubernetes objects.

🔹 Real-time Monitoring: With k9s, you can monitor the status and health of your cluster resources in real-time. It provides continuous updates and visual indicators for resource changes, including pod logs, events, and metrics.

🔹 Effortless Resource Management: k9s simplifies resource management tasks. It allows you to create, edit, delete, scale, and update various Kubernetes resources using simple keyboard shortcuts and commands. This streamlines common operations and reduces the need for manual YAML editing.

🔹 Customizable Views: k9s allows you to customize the UI layout and configure the displayed resource information. You can choose which columns to show, apply filters, and define custom views tailored to your specific needs.

🔹 Command Execution: k9s provides the capability to execute commands inside a pod container directly from the UI. This eliminates the need to switch to a separate terminal window for debugging or troubleshooting purposes.

🔹 Context Switching: k9s support the management of multiple Kubernetes contexts. You can easily switch between different clusters or namespaces without leaving the k9s interface.

Overall, k9s offer a more streamlined and interactive approach to managing Kubernetes clusters. It enhances productivity and provides a visual representation of resources, making it easier to navigate, monitor, and interact with your cluster.

Keep in mind that k9s is a separate tool and not a replacement for `kubectl`. You would still need `kubectl` for certain advanced operations or when working with commands or features not supported by k9s.

I hope this clarifies what k9s is and how it can benefit your Kubernetes management workflow.

Why do we need K9s and kubectl?

Kubectl and k9s are both valuable tools for managing Kubernetes clusters, but they serve different purposes.

Kubectl: It is the official command-line interface (CLI) tool provided by Kubernetes. It allows you to interact directly with the Kubernetes API server and perform various administrative tasks, such as deploying and managing applications, configuring resources, querying cluster information, and accessing logs and metrics. `kubectl` provides precise control over individual operations and is essential for executing advanced or specific commands not supported by other tools.

K9s: It is an alternative CLI tool that offers a more intuitive and user-friendly experience for managing Kubernetes clusters. It provides a terminal-based UI with features like efficient resource navigation, real-time monitoring, interactive commands, and customizable views. k9s simplifies common operations, enhances visibility into cluster resources, and speeds up everyday tasks, making it suitable for both beginners and experienced Kubernetes users. However, k9s may not support all the advanced functionalities of `kubectl` and may still require `kubectl` for certain tasks.

In summary, `kubectl` is the command-line tool that offers the most control over Kubernetes operations and is essential for advanced tasks, while `k9s` provides a more user-friendly and interactive experience for managing and monitoring clusters, especially for day-to-day operations.

Let me know if you have any further questions! 🐾

Connect to Huawei Cloud ECS

If you don't have a Huawei cloud account you can create a free account. Then learned a lot of things about Huawei Cloud, Huawei Koolabs, and the Huawei developer forum.

Huawei Cloud Elastic Cloud Service
ECS - EIP

We need a machine for remote connection like SSH on the Huawei cloud computing engine. Will use kubectl and k9s for some commands and configurations. Install kubectl and connection configuration on kubeconfig.

Install Kubectl

Checking kubectl on Linux terminal.

Checking kubectl

Copy the script or GitHub gist link.

# kubecl.sh
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

# test with kubectl
kubectl --help
Kubectl script

Paste the script on the sh file then save and run the file.

kubectl.sh running

Again check the kubectl. Must be like the below image.

Kubectl command help

Install k9s

K9s

Check the k9s on the terminal like this:

checking k9s

Copy and paste k9s script. Check save and run the script.

K9s.sh script
K9s script output

K9s script output like up image. Then check k9s.

Checking k9s
K9s Dashboard
K9s Dashboard

The K9 dashboard must be up with images.

How to use kubectl and k9s?

Scripts are here click -> https://gist.github.com/rabiayilmazz/15e3effff7d94fa292d5949ce60d0045

🐾 All scripts are below, or you can copy from the GitHub gist URL.

Using kubectl:
1. Install `kubectl` by following the official installation guide for your operating system.
2. Configure `kubectl` to connect to your Kubernetes cluster. You can do this by setting up the Kubernetes configuration file (`kubeconfig`) or by using environment variables.
3. Once set up, you can start using `kubectl` commands. Here are a few common examples:
1. `kubectl get pods` — List all pods in the cluster.
2. `kubectl create deployment my-app — image=my-image` — Create a new deployment called “my-app” using the “my-image” container image.
3. `kubectl describe pod my-pod` — Get detailed information about a specific pod named “my-pod”.
4. `kubectl delete deployment my-app` — Delete the deployment named “my-app”.

Please note that the above commands are just examples, and there are numerous other commands and options available in `kubectl`.

Using k9s:
1. Install `k9s` by following the official installation guide for your operating system.
2. Once installed, open your terminal and run the `k9s` command.
3. `k9s` will launch a terminal-based UI that provides a menu-driven interface to interact with your Kubernetes cluster.
4. Use the arrow keys to navigate through the different resources such as pods, deployments, services, and namespaces.
5. Press `Enter` to view detailed information about a selected resource.
6. Use shortcut keys (listed in the UI) to perform operations like deleting, editing, creating resources, or toggling various views.
7. Press `q` to exit `k9s`.

`k9s` provides an interactive and user-friendly way to manage and monitor your cluster resources. It is recommended to explore the tool’s documentation or help menu (`?` key within `k9s`) to discover more features and shortcuts.

Remember, for both `kubectl` and `k9s`, it’s important to have the necessary permissions and access to the Kubernetes cluster you’re working with.

Conclusion

I hope this article gives you a better understanding of what kubectl and k9s are and their importance in managing Kubernetes clusters. If you have any further questions or need additional assistance, feel free to ask! 😊

References

--

--