Introduction
In Chapter 1, Introduction to Kubernetes and Containers, we saw that Kubernetes is a portable and highly extensible open-source container orchestration tool. It provides very powerful capabilities that can be used to manage containerized workloads at scale. In the previous chapter, you got the big picture of how the different components of Kubernetes work together to achieve the desired goals. We also demonstrated some basic usage of kubectl in Chapter 2, An Overview of Kubernetes. In this chapter, we will take a closer look at this utility and look at how we can make use of its potential.
To reiterate, kubectl is a command-line utility for interacting with Kubernetes clusters and performing various operations. There are two ways to use kubectl while managing your cluster - imperative management, which focuses on commands rather than the YAML manifests to achieve the desired state, and declarative management, which focuses on creating and updating YAML manifest files. kubectl can support both these management techniques to manage Kubernetes API objects (also called Kubernetes API primitives). In the previous chapter, we saw how the various components constantly try to change the state of the cluster from the actual state to the desired state. This can be achieved by using kubectl commands or YAML manifests.
kubectl allows you to send commands to Kubernetes clusters. The kubectl command can be used to deploy applications, inspect, and manage Kubernetes objects, or troubleshoot and view logs. Interestingly, even though kubectl is the standard tool for controlling and communicating with a Kubernetes cluster, it doesn't come with Kubernetes. So, even if you are running kubectl on any of the nodes of your cluster, you need to install the kubectl binary separately, which we did in Exercise 2.01, Getting Started with Minikube and Kubernetes Clusters, in the previous chapter.
This chapter will walk you through the behind-the-scenes functionality of kubectl and provide more insights into how to use kubectl commands to interact with some commonly used Kubernetes objects. We will learn how to set up some shortcuts for kubectl. We will walk you through not only creating new objects with kubectl but also making changes to a live Deployment in Kubernetes. But before that, let's take a peek behind the curtains and get an idea of exactly how kubectl communicates with Kubernetes.