Top 20 Kubernetes Commands You Should Know [Chapter 1]

Manikanta - Nov 4 - - Dev Community

Image description
Kubernetes (K8s) is a powerful platform for managing containerized applications. Familiarity with essential Kubernetes commands can significantly improve your productivity and help you troubleshoot issues more effectively. Below, we’ll cover 20 of the most important Kubernetes commands, along with simple explanations.

1.kubectl get
Use this command to list resources. You can specify the resource type (like pods, services, deployments) to get a concise view of what's running.

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

2.kubectl describe
This command provides detailed information about a specific resource, including events, status, and configuration.

kubectl describe pod <pod-name>
Enter fullscreen mode Exit fullscreen mode

3.kubectl create
Use this command to create a resource from a file or directly in the command line.

kubectl create -f <file.yaml>
Enter fullscreen mode Exit fullscreen mode

4.kubectl apply
This command updates a resource by applying changes from a file. It can create the resource if it doesn't exist.

kubectl apply -f <file.yaml>

Enter fullscreen mode Exit fullscreen mode

5.kubectl delete
Use this command to delete a resource. You can specify the resource type and name.

kubectl delete pod <pod-name>
Enter fullscreen mode Exit fullscreen mode

6.kubectl logs
This command retrieves logs from a specified pod, which is useful for debugging.

kubectl logs <pod-name>
Enter fullscreen mode Exit fullscreen mode

7.kubectl exec
Use this command to execute a command inside a running container within a pod.

kubectl exec -it <pod-name> -- /bin/bash
Enter fullscreen mode Exit fullscreen mode

8.kubectl port-forward
This command allows you to forward a local port to a port on a pod, which is useful for accessing services locally.

kubectl port-forward <pod-name> <local-port>:<pod-port>
Enter fullscreen mode Exit fullscreen mode

9.kubectl scale
Use this command to scale a deployment up or down by specifying the desired number of replicas.

kubectl scale deployment <deployment-name> --replicas=<number>
Enter fullscreen mode Exit fullscreen mode

10.kubectl rollout
This command manages the rollout of a resource, such as deploying a new version or rolling back to a previous version.

kubectl rollout status deployment <deployment-name>
Enter fullscreen mode Exit fullscreen mode

11.kubectl get nodes
This command lists all the nodes in your Kubernetes cluster, showing their status and roles.

kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

12.kubectl get services
Use this command to list all services in the cluster, which helps you understand how different parts of your application communicate.

kubectl get services
Enter fullscreen mode Exit fullscreen mode

13.kubectl get deployments
This command lists all deployments, providing an overview of your application’s desired state.

kubectl get deployments
Enter fullscreen mode Exit fullscreen mode

14.kubectl top
This command shows resource usage (CPU and memory) of nodes or pods, which is helpful for monitoring performance.

kubectl top pods
Enter fullscreen mode Exit fullscreen mode

15.kubectl config
This command allows you to modify kubeconfig settings, such as changing the current context.

kubectl config current-context
Enter fullscreen mode Exit fullscreen mode

16.kubectl namespace
Use this command to manage namespaces in your Kubernetes cluster, which helps organize resource

kubectl create namespace <namespace-name>
Enter fullscreen mode Exit fullscreen mode

17.kubectl cp
This command copies files between your local filesystem and a pod.

kubectl cp <local-file-path> <pod-name>:<remote-file-path>
Enter fullscreen mode Exit fullscreen mode

18.kubectl get events
This command lists events in your cluster, which can help you diagnose issues by showing what’s happening behind the scenes.

kubectl get events
Enter fullscreen mode Exit fullscreen mode

19.kubectl edit
Use this command to edit a resource in your default editor, allowing for quick changes without creating a new file.

kubectl edit deployment <deployment-name>
Enter fullscreen mode Exit fullscreen mode

20.kubectl api-resources
This command lists all API resources available in your Kubernetes cluster, helping you discover new types you might want to use.

kubectl api-resources
Enter fullscreen mode Exit fullscreen mode

Conclusion
Understanding these Kubernetes commands will enhance your ability to manage and troubleshoot your applications in a Kubernetes environment. Whether you’re a beginner or an experienced user, these commands are vital for navigating the complexities of container orchestration. Happy K8s-ing!

. .
Terabox Video Player