Make Your Terminal DevOps and Kubernetes Friendly

If you work with DevOps and Kubernetes, you know how important the command line interface (CLI) is for managing tasks. Fortunately, there are tools available that make the terminal easier to use in these environments. In this article, we’ll explore some top tools that simplify your workflow and help you navigate the terminal with confidence in DevOps and Kubernetes.

ZSH

Zsh (Z Shell) is a powerful and highly customizable command-line shell and terminal emulator that offers enhanced features and productivity improvements over traditional shells like Bash. Providing the following options makes it a popular choice among developers and DevOps engineers.

ohmyzsh

Oh My Zsh is an open-source, community-driven framework for managing your Zsh configuration. You can install it with curl as below:

sh -c "$(curl -fsSL <https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh>)"

zsh-syntax-highlighting

zsh-syntx-highlighting is a plugin for the Zsh shell that provides real-time syntax highlighting for commands and their arguments as you type. It helps visually distinguish between different types of commands, options, paths, and variables, making it easier to spot errors and understand the structure of your commands in the terminal.

Follow the installation guide HERE.

This is what my terminal looks like before and after installing the tool:

Before installation
After installation

zsh-autosuggestions

zsh-autosuggestions is a helpful plugin for the Zsh shell that offers intelligent command suggestions as you type. It analyzes your command history and provides predictive suggestions for completing commands.

Follow the installation guide HERE.

This is what my terminal looks like before and after installing the tool:

Before installation
After installation

Terraform

If you work with Terraform and Terragrunt as Infrastructure as Code tools, then you might find the below relevant tools useful while working with Terraform and Terragrunt.

tfswitch and tgswitch

Tfswitch and tgswitch are command line tools that simplify switching between different versions of the Terraform and Terragrunt infrastructure-as-code tools. They allow developers and operators to easily manage and switch between different versions of Terraform and Terragrunt for different projects or environments.

On Mac, you can install these tools as below:

brew install warrensbox/tap/tfswitch
brew install warrensbox/tap/tgswitch

NOTE: For Terraform and Terragrunt installations to work with tfswitch and tgswitch on Mac with Zsh, you might need to add the below line to your .zshrc file.

export PATH=$HOME/bin:/usr/local/bin:$PATH

Infracost

Infracost is a powerful tool that helps you estimate and track the cost of your infrastructure as code (IaC) in platforms like Terraform. By analyzing your infrastructure configuration files, Infracost provides real-time cost estimates, allowing you to make informed decisions and optimize your cloud spending by identifying potential cost-saving opportunities.

This tool also has a Visual Studio Code (VSCode) extension.

This is what I got running it for a project:

TfSec

TFSec is a security scanning tool specifically designed for Terraform code. It helps identify potential security vulnerabilities and best practice violations in your infrastructure as code, allowing you to proactively address security concerns and ensure compliance with industry standards and organizational policies.

You can install it on Mac as below:

brew install tfsec

This is what I got running it for my project:

Git

There are also some tools that make your life easier if you work with Git!

Git aliases

Using aliases for Git offers numerous benefits, including enhanced productivity and efficiency by minimizing the need to repeatedly type lengthy Git commands. If you frequently work with Git, it is recommended to define aliases for commonly used Git commands in your .zshrc file. Here’s an example section to help you get started:

# Git aliases
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gpl='git pull'
alias gb='git branch'

By defining these aliases in your shell configuration file (e.g., .bashrc or .zshrc), you can simply type the alias instead of the full Git command to execute common operations, saving you time and effort in your daily Git workflow.

GitLens

GitLens is a helpful extension for VSCode that provides valuable insights and additional functionality when working with Git repositories. It enables users to easily track changes, view commit details, and understand code authorship directly within the code editor, enhancing collaboration and making it easier to navigate and explore the history of a project.

Once you enable the GitLens extension in Visual Studio Code, you will see clear indications of code authorship:

Git Graph

Git Graph is a user-friendly extension for Visual Studio Code that displays a visual representation of your Git repository’s commit history. It allows you to easily visualize branches, merges, and commits, providing a helpful overview of the project’s development timeline and making it simpler to navigate and understand the structure of your Git repository.

Kubernetes

Due to the complexity of Kubernetes, many additional tools have been created to assist DevOps teams in effectively utilizing it. These tools are designed to simplify the process, allowing DevOps professionals to seamlessly work with Kubernetes and optimize their deployment and management tasks.

Kubernetes aliases

Just like using aliases for Git commands, utilizing aliases for Kubernetes commands is also beneficial. Aliases can make working with Kubernetes commands easier and more efficient, saving time and effort when interacting with Kubernetes clusters and resources.

alias k='kubectl'
# For switching context between different clusters
alias kswitch-maryam='kubectl config use-context maryam'
alias kswitch-mary='kubectl config use-context mary'alias kpod='kubectl get pods -A'
alias knode='kubectl get nodes'
alias kdesp='kubectl describe pod'
alias kdp='kubectl delete pod'
alias kgd='kubectl get deployments'

These are just a few examples, and you can customize aliases based on your frequently used Kubernetes commands. By adding these aliases to your shell configuration file (e.g., .bashrc or .zshrc), you can use these shortcuts to execute Kubernetes commands quickly and easily.

kube-ps1

Kube-ps1 enhances your command prompt with relevant information about your current Kubernetes context. It has been incredibly helpful for me while working with multiple Kubernetes clusters and managing different cluster contexts. Visually highlighting the details of the active cluster context, it has saved me from potential mistakes and provided clarity in navigating and interacting with Kubernetes environments.

You can install it on Mac as follow:

brew install kube-ps1

If you work with Zsh, make sure to add the below to your .zshrc file:

plugins=(
  kube-ps1
)
PROMPT='$(kube_ps1)'$PROMPT # or RPROMPT='$(kube_ps1)'

This is how this tool visualizes your current active context and namespace:

kubecolor

Kubecolor is a handy tool that enhances the output of Kubernetes commands with color and formatting, making it easier to read and understand. Kubecolor improves visibility and helps quickly identify important information when working with Kubernetes. (Its again one lifesaver tool while daily working with Kubernetes!)

Install it as below on Mac and make sure to add the second line to your .zshrc for it to work with kubectl auto-complete:

brew install hidetatz/tap/kubecolor
# get zsh complete kubectl
source <(kubectl completion zsh)
alias kubectl=kubecolor
# make completion work with kubecolor
compdef kubecolor=kubectl

This is an example of how this tool colorizes the output of Kubernetes commands:

kubectx + kubens

Kubectx and kubens are helpful tools for managing Kubernetes contexts and namespaces. Kubectx allows users to switch between different Kubernetes contexts, while Kubens simplifies switching between namespaces within a specific context, making it easier to work with multiple clusters and organize resources efficiently.

K9s

K9s is a user-friendly command-line tool that provides a visual dashboard for managing Kubernetes clusters. It offers a simple and intuitive interface to view and interact with resources, pods, logs, and events, making it easier for DevOps professionals to monitor and troubleshoot their Kubernetes deployments.

k8s Lens

K8s Lens is a user-friendly desktop application that provides a graphical interface for managing and monitoring Kubernetes clusters. It offers a visual representation of resources, pods, and nodes, allowing users to easily navigate and interact with their Kubernetes environments, making it convenient for developers and administrators to work with Kubernetes.

popeye

Popeye is a helpful command-line tool that analyzes Kubernetes clusters and provides valuable insights regarding potential issues or misconfigurations. It scans the cluster configuration, namespaces, deployments, and pods to identify best practices violations, resource inefficiencies, and security concerns, helping users ensure their Kubernetes deployments are optimized and well-maintained.

This is the example information that scanning a cluster, Popeye will give you:

Install the tool on Mac as below:

brew install derailed/popeye/popeye

Kube-shell

Kube-shell is an integrated shell for Kubernetes CLI. It offers a user-friendly interface with visual representations of cluster resources, allowing users to easily navigate, monitor, and manage their Kubernetes deployments without needing to rely on command-line interfaces.

Kube-Capacity

Kube-Capacity is a handy tool that provides insights into the resource usage and capacity of your Kubernetes cluster. It helps you understand how your cluster’s resources are allocated and utilized, allowing you to optimize resource allocation, plan for scaling, and ensure efficient resource management within your Kubernetes environment.

Last updated