Useful CLI tools for DevOps Engineers

Jeewan Sooriyaarachchi
4 min readOct 3, 2021

--

These are set of tools I have being using and observed /learned from my co-workers. Using the right tools and technques will greatly improve our productivity and deliver more values to our role. Some of them listed here are pretty obvious but I added them here for completeness. I would like to hear similar tools you have been using in the comment section.

Most of these tools are open source, ensure you don’t violate any of your company policies by using them

Source: https://www.bhg.com/home-improvement/advice/expert-advice/best-tool-kits/

These are tools to be installed on your workstation or laptop but not on the servers

Cloud CLI

Most of us using IaC tools such as Terraform, Cloudformation for cloud resource administration. But we often need to find out details about resources for variours reasons such as troubleshooting and etc. We can use cloud web portals for this task but it often take longer time to authenticate and load the pages. But using the CLI tools are more effective once you get familiar with the set of commands. These are CLI tools for most popular cloud providers

fzf

This is a linux background tool to select arguments from list of options and so on. It complements below list of tools. You will get better idea once you go through the details mentioned in kubectx github page

https://github.com/junegunn/fzf

kubectx

This is helpful to switch between kubernetes clusters for those who are dealing with multiple clusters. It reads the ~/.kube/config file and let you choose the one required.

https://github.com/ahmetb/kubectx

kubens

This tool lets you select the default namespace of the cluster. Whenever you run kubectl commands, its difficult to specify namespace in each and every command. This command will help you to quickly switch between namespaces

https://github.com/ahmetb/kubectx

stern

This is a another tool for easily viewing the logs of all the pods and containers of a particular deployment. Stern output is color coded and easily distinguish the logs of different pods and containers. Hence its easy to debug with stern instead of using kubeclt logs command.

stern <deployment-name>

https://github.com/wercker/stern

Here is the equivalent kubectl command.

kubectl logs -f deployemnet/nginx --all-containers=true

awsp

Again this is a tool to easily switch between AWS accounts without manually configuring default profile.

https://github.com/johnnyopao/awsp

tfenv

If you are using terraform for infrastructure creation, it is common you will end up with multiple terraform version over the time. This tool helps you to select the current active version of terraform as well as install or uninstall required versions.

tfenv use 0.13.0

https://github.com/tfutils/tfenv

tgenv

This is a equivalent of tfenv for terragrunt

tgenv use 0.28.3

aws-vault

Once you install and configure AWS CLI it generally stores access keys and secrets in ~/.aws/credentials file in plain text which is not very secure. Instead, you can use aws-vault to store those security credentials and lock it with another password you prefer. But you will have to run all the aws account under aws-vault terminal.

aws-vault add profile name<< Add the account details with profile name

aws-vault exec profile aws sts get-caller-identity << Run any AWS CLI command on aws-vault exec profile

https://github.com/99designs/aws-vault

Setup bash PS1

This is nothing special than setting your shell prompt to display the useful infromation. For example, you can configure it to diplay the currently connected server name, username, kubernetes cluster, AWS account or so on as per your desire. Idea is to be aware about the environment we are connected to before execute any critical commands. For an example, someone might connected to production but executing commands assumings its staging or development environment. These bash prompts will help to minimize those mistakes.

Here is an example to show the color coded ‘[username@hostname:/current-dir] (branch of git repo)’. This has to be added to to ~/.bashrc of bash users.

parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\[\e[32m\][\[\e[m\]\[\e[31m\]\u\[\e[m\]\[\e[33m\]@\[\e[m\]\[\e[32m\]\h\[\e[m\]:\[\e[36m\]\w\[\e[m\]\[\e[32m\]]\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\[\e[m\]\[\e[32m\] >\[\e[m\] "

Kube-ps1

This allows you to display current k8s context and namespace (by default) in your terminal by updating the PS1. Good thing is it can be easily turned off and on whenever you require it.

https://github.com/jonmosco/kube-ps1

Github cli

This is only valid for people use Github as their source control system. Github has a CLI tool which can do most of the stuff you can do on github web portal. But most useful one for me is to create pull requests easily from my current local branch.

gh pr create --title "Title for PR" --body "Detailed description of pr"

https://github.com/cli/cli

docker-credential-helper-ecr

If you are dealing with lot of docker image creation, pushing and pulling images from Amazon container registry, this is a useful tool to ease the authentication with ECR.

helm-switcher

Similar to tfenv/tgenv, you can use helm-switcher to install required helm versions and switch between them easily. You just have to download the binary and save in executable path.

https://github.com/tokiwong/helm-switcher

Thanks for reading and those are the list of tools I can list down on top of my head. But I will keep on updating as I learn and discover more.

--

--

Responses (3)