Chapter 12. Maintenance and Troubleshooting

In this chapter, you will find recipes that deal with both app-level and cluster-level maintenance. We cover various aspects of troubleshooting, from debugging pods and containers to testing service connectivity, interpreting a resource’s status, and maintaining nodes. Last but not least, we look at how to deal with etcd, the Kubernetes control-plane storage component. This chapter is relevant for both cluster admins and app developers.

12.1 Enabling Autocomplete for kubectl

Problem

It is cumbersome to type full commands and arguments for the kubectl CLI, so you want an autocomplete function for it.

Solution

Enable autocompletion for kubectl.

For the bash shell, you can enable kubectl autocompletion in your current shell with the following command:

$ source <(kubectl completion bash)

Add this to your ~/.bashrc file so that autocomplete loads in all of your shell sessions:

$ echo 'source <(kubectl completion bash)' >>~/.bashrc

Note that autocompletion for bash depends on bash-completion being installed.

For the zsh shell, you can enable kubectl autocompletion with the following command:

$ source <(kubectl completion zsh)

And you can add this same command to your ~/.zshrc file for autocomplete to load in all your shell sessions.

For autocompletion to work in zsh, you may need to have these commands at the start of your ~/.zshrc file:

autoload -Uz compinit
compinit

For other operating systems and shells, please check the documentation ...

Get Kubernetes Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.