What is kubectl?
Kubectl is command-line software that helps to run commands in the Kubernetes Cluster. It acts as a bridge between clients and the Kubernetes cluster providing communication through API requests using http or https protocols. It converts the commands entered in the command line from a user into API requests and pass to the API server of the Kubernetes master Node with proper Authentication. It helps to manage the containers and deploy apps and other resources to run smoothly.
Architecture of Kubectl in Kubernetes Cluster
The Kubectl is a client-side tool that acts as a bridge between the users and the K8s cluster. It provides an interactive command-line interface for the users to run the commands with kubectl against the Kubernetes cluster. The Architecture involves once the users/ client executes a command through the command line it is authenticated with the master node of k8s Cluster through the Kubernetes API server. Based on the type of API request Kubernetes API server facilitates the orchestration and coordination of Kubernetes resources such as Control Manager, Kubernetes Scheduler, and Etcd resources.. within the Kubernetes Cluster.
Syntax
The syntax for running the kubectl command is as follows:
kubectl [command] [TYPE] [NAME] [flags]
Command refers to the operation to be performed on the cluster. A few examples include create , delete and describe.
TYPE refers to the resource type on which the operation needs to be performed. The resource type is not sensitive to upper or lower-case characters used when writing the command. Thus, regardless of capitalization, the same resource type will be recognized by kubectl.
NAME refers to the name of the resource. Unlike TYPE, resource names are case-sensitive. Thus, capital and lowercase letters will give a different output.
Flags is an optional part of the syntax and is used to mention the port number of the Kubernetes API server.
Note: A kubectl command can be applied to one or more resources and resource types.
What are kubectl plugins?
Kubectl performs basic operations on Kubernetes clusters. To ensure the tool exhibits complex behavior and executes intricate functions, kubectl plugins can be written and installed in the infrastructure. These can be pre-existing plugins or custom-made ones, depending on the needs of the application and the functions it must execute. A few of the plugins are listed below:
Kubescape
The Kubescape plugin focuses on Kubernetes cluster security by offering risk analysis, security compliance, and misconfiguration scanning. The easy-to-use CLI makes it simple to take advantage of flexible output formats and initiate automated scanning capabilities.
Stern
The Kubernetes Stern plugin is a command-line tool that allows users to tail multiple container logs in a Kubernetes cluster. It provides a way to easily view and follow the logs of multiple containers across multiple pods, without having to manually open individual log files or SSH into each container.
Kubepug
Kubernetes releases newer versions periodically, and engineers find it difficult to learn which APIs are removed, what upgrades have been made, and more. Kubepug enables Kubernetes engineers to know these details before migrating the infrastructure to a newer version.
Ingress-nginx
Ingress-nginx simplifies ingress operations on clusters and easily allows external services to access Kubernetes clusters. Thus traffic routing and resource management become simpler.
List of major kubectl operations
Operation | Syntax | Description |
get | kubectl get po -o wide | Lists detailed information for all pods. |
create | kubectl create -f filename | Creates a cluster resource from a file or other input. |
expose | kubectl expose deployment deployname –port=81 –type=NodePort –target-port=80 –name=service-name | Exposes a resource, such as a pod, service or deployment, as a new Kubernetes service. |
run | kubectl run deployname –image=nginx:latests] | Runs a particular image in a cluster. |
set | kubectl set image deploy deployname containername=containername:1.0 | Changes the image of a deployment with the name specified in deployname to image 1.0 |
edit | kubectl edit po po-nginx-btv4j | Updates a pod using the default editor. |
explain | kubectl auth [flags] [options] | Views documents or reference materials related to the specified subject. |
autoscale | kubectl autoscale | Automatically scale the set of pods that are managed by a replication controller. |
delete | kubectl delete po podname | Deletes resources by name or label.. |
rollout | kubectl rollout status/history deployment/deployname | Check the rollout status or history of a particular deployment |