Community post originally published on Dev.to by Syed Asad Raza

Kubernetes is a powerful container orchestration platform, but its capabilities can be significantly extended with plugins. Plugins provide additional functionality that can enhance the operational capabilities of your Kubernetes clusters, streamline workflows, and add features not available out of the box. In this guide, we’ll explore how to install plugins in Kubernetes and discuss some essential plugins to help you get started.

What Are Kubernetes Plugins?

Kubernetes plugins, or “kubectl plugins,” are tools that extend the functionality of the kubectl command-line tool. These plugins can be developed by the community or Kubernetes administrators to add specific features or automate tasks. They are designed to be seamlessly integrated into your existing Kubernetes setup, providing extra capabilities while maintaining the core functionality of Kubernetes.

Why Use Kubernetes Plugins?

Plugins can help you:

Installing Plugins in Kubernetes

To install plugins in Kubernetes, follow these steps:

Step 1: Set Up Your Environment

Ensure you have the following prerequisites:

Step 2: Install Krew

Krew is a plugin manager for kubectl that makes it easy to discover and install plugins. Follow these steps to install Krew:

  1. Download Krew:
(
  set -x; cd "$(mktemp -d)" &&
  OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
  ARCH="$(uname -m | sed 's/x86_64/amd64/;s/arm.*/arm/;s/aarch64$/arm64/')" &&
  KREW="krew-${OS}_${ARCH}" &&
  curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
  tar zxvf "${KREW}.tar.gz" &&
  ./"${KREW}" install krew
)
  1. Add Krew to your PATH:
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
  1. Verify the installation:
kubectl krew

You should see a list of Krew commands if the installation was successful.

Step 3: Install Plugins Using Krew

With Krew installed, you can now search for and install plugins. Here’s how:

  1. Search for plugins:
kubectl krew search

This command lists all available plugins.

  1. Install a plugin: For example, to install the kubectl neat plugin, which cleans up Kubernetes manifests to make them more readable, run:
kubectl krew install neat
  1. Use the installed plugin: You can now use the plugin by prefixing the command with kubectl. For example:
kubectl neat -f my-pod.yaml

This command will clean up the my-pod.yaml file to make it more readable.

Essential Kubernetes Plugins to Get Started

Here are some essential plugins that every Kubernetes user should consider installing:

  1. kubectl-neat Purpose: Simplifies Kubernetes manifests by removing clutter, such as managed fields and default values, making them easier to read and understand.

Installation:

kubectl krew install neat

Usage:

kubectl get pod my-pod -o yaml | kubectl neat
  1. kubectl-ctx and kubectl-ns Purpose: Quickly switch between different Kubernetes contexts and namespaces. These plugins help manage multiple clusters and namespaces efficiently.

Installation:

kubectl krew install ctx
kubectl krew install ns

Usage:

kubectl ctx    # List all contexts
kubectl ctx my-context    # Switch to 'my-context'
kubectl ns my-namespace   # Switch to 'my-namespace'
  1. kubectl-who-can Purpose: Helps identify which users or service accounts have permission to perform specific actions in the cluster. This is particularly useful for debugging RBAC issues.

Installation:

kubectl krew install who-can

Usage:

kubectl who-can create pods
  1. kubectl-view-secret Purpose: It makes it easier to view Kubernetes secrets. The plugin decodes base64-encoded secrets in a human-readable format.

Installation:

kubectl krew install view-secret

Usage:

kubectl view-secret my-secret
  1. kubectl-replace-image Purpose: Allows for easy replacement of container images in a running Kubernetes Deployment. This is useful when you want to quickly change the image of a deployment without editing the manifest file.

Installation:

kubectl krew install replace-image

Usage:

kubectl replace-image deployment/my-deployment container-name=new-image:tag

Conclusion

Plugins are a powerful way to extend Kubernetes’ functionality and streamline workflows. Using Krew to install and manage plugins, you can easily add new features to your Kubernetes toolkit and improve your cluster management capabilities. Start with the essential plugins mentioned in this guide and explore the extensive list of available plugins to find tools that best suit your needs.