Cloud Native 9 min read

Essential Kubernetes Commands for Testers: 50 Commands with Practical Examples

This article presents a comprehensive collection of 50 essential kubectl commands covering cluster, namespace, pod, deployment, service, ConfigMap, secret, volume, logging, debugging, scaling, configuration, and cleanup operations, providing testers with practical examples to efficiently manage and troubleshoot Kubernetes environments.

Test Development Learning Exchange
Test Development Learning Exchange
Test Development Learning Exchange
Essential Kubernetes Commands for Testers: 50 Commands with Practical Examples

Kubernetes is a widely adopted container orchestration platform, and mastering its command‑line tools is crucial for testers who need to validate and deploy containerized applications. The following guide lists 50 indispensable kubectl commands, grouped by functional area, and includes practical usage examples.

Cluster Operations : List nodes ( kubectl get nodes ), view cluster info ( kubectl cluster-info ), inspect events ( kubectl get events ), and check component statuses ( kubectl get componentstatuses ).

Namespace Operations : Show namespaces ( kubectl get namespaces ), create a namespace ( kubectl create namespace <name> ), and switch the current namespace ( kubectl config set-context --current --namespace=<name> ).

Pod Operations : List pods ( kubectl get pods ), describe a pod ( kubectl describe pod <pod-name> ), create a pod from a YAML file ( kubectl create -f <file.yaml> ), delete a pod ( kubectl delete pod <pod-name> ), and exec into a pod ( kubectl exec -it <pod-name> -- /bin/bash ).

Deployment Operations : List deployments ( kubectl get deployments ), describe a deployment ( kubectl describe deployment <name> ), create or update a deployment via YAML ( kubectl create -f <file.yaml> , kubectl apply -f <file.yaml> ), and scale replicas ( kubectl scale deployment <name> --replicas=<num> ).

Service Operations : List services ( kubectl get services ), describe a service ( kubectl describe service <name> ), create a service from YAML ( kubectl create -f <file.yaml> ), and delete a service ( kubectl delete service <name> ).

ConfigMap Operations : List ConfigMaps ( kubectl get configmaps ), describe a ConfigMap ( kubectl describe configmap <name> ), create from files ( kubectl create configmap <name> --from-file=<path> ), and update ( kubectl apply -f <file.yaml> ).

Secret Operations : List secrets ( kubectl get secrets ), describe a secret ( kubectl describe secret <name> ), create a generic secret ( kubectl create secret generic <name> --from-literal=<key>=<value> ), and update with kubectl apply -f .

Volume Operations : List PersistentVolumes ( kubectl get pv ) and PersistentVolumeClaims ( kubectl get pvc ), create a PVC ( kubectl create -f <file.yaml> ), and list StorageClasses ( kubectl get storageclasses ).

Logging and Debugging : View pod logs ( kubectl logs <pod-name> ) and follow logs ( kubectl logs -f <pod-name> ), list containers in a pod using a jsonpath command, and execute arbitrary commands inside a pod ( kubectl exec <pod-name> -- <command> ).

Debugging and Troubleshooting : Run a temporary debugging container ( kubectl run -i --tty --image=<image> --restart=Never -- sh ), describe pod status ( kubectl describe pod <name> ), and view resource usage ( kubectl top pod ).

Scaling and Automation : Scale a ReplicaSet ( kubectl scale rs <name> --replicas=<num> ), scale a StatefulSet ( kubectl scale statefulset <name> --replicas=<num> ), and enable autoscaling for deployments ( kubectl autoscale deployment <name> --min=<min> --max=<max> --cpu-percent=<percent> ).

Configuration Management : View kubeconfig files ( kubectl config view ), switch context ( kubectl config use-context <context> ), and display cluster authentication details ( kubectl config view --minify --flatten -o jsonpath='{.clusters[0].cluster}' ).

Cleanup and Deletion : Remove all pods, services, and replica sets in a namespace ( kubectl delete pod,service,replicaset --all ), delete specific deployments, ConfigMaps, or secrets using kubectl delete deployment <name> , kubectl delete configmap <name> , and kubectl delete secret <name> .

These commands equip testers with the necessary tools to efficiently operate, debug, and maintain Kubernetes clusters, and the article encourages further study of the official Kubernetes documentation for deeper insights.

cloud nativeTestingKubernetesDevOpsCluster Managementkubectl
Test Development Learning Exchange
Written by

Test Development Learning Exchange

Test Development Learning Exchange

0 followers
Reader feedback

How this landed with the community

login 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.