Breaking
Latest technical intelligence from Northeast India • Infrastructure, AI, Cloud & Security Analysis • Precision Analysis | Raw Intelligence | Your North Star of Tech • Latest technical intelligence from Northeast India • Infrastructure, AI, Cloud & Security Analysis
LINUX

Analysis: Top 20 kubectl Commands Every Kubernetes Beginner Must Know

Mastering Kubernetes with 20 Essential Commands

Mastering Kubernetes with 20 Essential Commands

In the ever-evolving world of cloud-native applications, Kubernetes has emerged as the de facto standard for container orchestration. With its robust features and scalable architecture, Kubernetes has become the go-to platform for developers, DevOps engineers, and SREs worldwide. However, mastering Kubernetes can be an intimidating task, especially for those new to the platform. This article aims to simplify the process by introducing you to 20 essential kubectl commands that will empower you to effectively manage your Kubernetes cluster.

Navigating Kubernetes Resources: kubectl get

The kubectl get command is the primary tool for retrieving information about various Kubernetes resources such as Pods, Services, Deployments, and Nodes. This command is extensively used to gain an overview of the current state of the cluster.

  • kubectl get pods: List all pods in the current namespace.
  • kubectl get deployments: List all deployments.
  • kubectl get services: List all services.
  • kubectl get nodes: List all nodes in the cluster.
  • kubectl get all: Get all common resources (pods, deployments, services, replicasets) in the current namespace.
  • kubectl get pods -A or kubectl get pods all-namespaces: List pods across all namespaces.
  • kubectl get pods -o wide: Get more detailed output for pods, including node IP and internal IP.

Deep Dive: kubectl describe

While kubectl get provides a high-level snapshot of a Kubernetes resource, kubectl describe takes you behind the scenes. It provides details about the current state of the resource, including events, status, container specifications, mounted volumes, network details, and more.

  • kubectl describe pod
  • kubectl describe deployment
  • kubectl describe service

Troubleshooting Pods: kubectl logs and kubectl exec

When dealing with application-level issues in pods, kubectl logs and kubectl exec are invaluable tools. The former allows you to view logs from a pod, while the latter provides shell-level access to the container's environment.

  • kubectl logs
  • kubectl logs -c
  • kubectl exec -it -c -- /bin/bash

Managing Resources: kubectl apply and kubectl delete

The kubectl apply command is used to create or update Kubernetes resources based on a provided manifest file. Conversely, kubectl delete is used to remove resources from the cluster.

  • kubectl apply -f
  • kubectl delete pod
  • kubectl delete -f k8s.yaml

Interacting with Services: kubectl port-forward and kubectl scale

kubectl port-forward allows you to forward a local port to a specific pod or service within the cluster, while kubectl scale adjusts the number of running pods in a deployment.

  • kubectl port-forward my-pod 8080:80
  • kubectl port-forward svc/my-service 9090:80
  • kubectl scale deployment --replicas=5

Monitoring and Troubleshooting: kubectl top, kubectl version, and kubectl edit

kubectl top provides real-time CPU and memory statistics, kubectl version displays the version of kubectl and the Kubernetes cluster, and kubectl edit allows you to make on-the-fly modifications to live Kubernetes resources.

  • kubectl top pods
  • kubectl top nodes
  • kubectl version
  • kubectl edit deployment/hello-deployment

Advanced Features: kubectl diff, kubectl explain, kubectl proxy, kubectl autoscale, kubectl completion, kubectl cordon/uncordon, and kubectl debug

kubectl diff, kubectl explain, kubectl proxy, kubectl autoscale, kubectl completion, kubectl cordon/uncordon, and kubectl debug are advanced commands that provide additional functionality for managing and troubleshooting your Kubernetes cluster.

kubectl diff

Shows a line-by-line comparison between your local manifest and the current state of the resource in the cluster.

kubectl explain

Provides detailed documentation about Kubernetes resources and fields.

kubectl proxy

Allows you to access the Kubernetes API directly from your local machine.

kubectl autoscale

Dynamically adjusts the number of replicas to meet workload demands.

kubectl completion

Generates shell completion scripts for your chosen shell.

kubectl cordon/uncordon

Marks a node as unschedulable or reverses the action.

kubectl debug

Creates an ephemeral container in a running pod for debugging purposes.

Relevance to North East India and India

As a rapidly growing region with a burgeoning tech industry, North East India is poised to benefit significantly from the adoption of cloud-native technologies such as Kubernetes. By mastering essential kubectl commands, developers and DevOps engineers in the region can accelerate their learning curve and contribute to the growing cloud-native ecosystem in India.

Looking Ahead

Kubernetes is an ever-evolving platform, and new features and improvements are being introduced regularly. By continuously learning and expanding your knowledge of kubectl commands, you will be well-equipped to stay ahead of the curve and effectively manage your Kubernetes cluster in the years to come.