Cloud Native 5 min read

Mastering kubectl: Essential Commands for Kubernetes Management

This guide explains what kubectl is, how it interacts with the Kubernetes API server, and provides a categorized list of essential commands for retrieving information, debugging, state management, scaling, deployment, and security, helping users efficiently operate and automate K8s clusters.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering kubectl: Essential Commands for Kubernetes Management

What is kubectl?

kubectl is the command‑line tool for interacting with a Kubernetes (K8s) cluster. It sends REST requests to the API server, allowing users to query and manipulate resources such as Pods, Services, Deployments, and more. It supports both interactive and batch operations, making automation straightforward.

Information Retrieval

kubectl get – retrieve information about resources (nodes, services, pods, configmaps, etc.).

kubectl describe – show detailed information for a specific resource.

kubectl logs – fetch logs from a pod.

kubectl top – display CPU and memory usage of nodes and pods.

Debugging & Diagnosis

kubectl exec – run a command inside a container.

kubectl port-forward – forward a local port to a pod port, e.g.

kubectl --namespace monitoring port-forward --address 0.0.0.0 svc/prometheus-k8s 9090

kubectl run – create a new pod and run a container.

kubectl attach – attach to a running container.

kubectl debug – start a debugging container attached to a target pod.

State Management

kubectl create – create Kubernetes resources.

kubectl apply – apply declarative configuration to existing resources.

kubectl delete – delete resources.

kubectl edit – edit a resource’s configuration in an editor.

kubectl label – add or modify labels on resources.

kubectl annotate – add or modify annotations on resources.

Scaling

kubectl scale – increase or decrease replica count of Deployments, StatefulSets, etc.

kubectl autoscale – create a Horizontal Pod Autoscaler that adjusts replicas based on CPU or custom metrics.

Deployment Management

kubectl rollout – perform rolling updates for Deployments, DaemonSets, StatefulSets.

kubectl rollout history – view rollout history.

kubectl rollout undo – roll back a deployment.

kubectl patch – apply partial updates to resources.

Security & Authentication

kubectl auth – manage authentication and authorization.

kubectl create secret – create secrets for authentication/authorization.

kubectl certificate – manage TLS certificates and private keys.

For a complete list of commands and options, refer to the official documentation: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeKubernetesDevOpsCluster Managementkubectl
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.