Skip to main content

kubectl: The Kubernetes Commands

To interact with a Kubernetes cluster, we use a command-line tool called kubectl.

The basic syntax for every command is:

> kubectl [command] [TYPE] [NAME] [flags]

  • Command: What you want to do (get, describe, create, delete).

  • Type: The resource you are touching (pod, service, deployment, node).

  • Name: The specific name of the resource (optional if you want to list everything).

  • Flags: Extra options (like -n for namespace or -o for output format).

Must-Know Commands​

**CategoryCommandWhat it does (Simple English)**Viewingkubectl get podsLists all pods in the default namespace.kubectl get pods -o wideShows more details like IP address and Node name.kubectl get allShows pods, services, deployments, etc.Inspectionkubectl describe pod [name]"Show me the medical report." Gives detailed history/errors.kubectl logs [pod-name]"Show me the diary." See what the application printed out.Actionkubectl delete pod [name]Deletes the pod (K8s will usually restart it!).kubectl apply -f [file.yaml]"Make it happen." Creates/Updates resources from a file.Accesskubectl exec -it [pod-name] -- /bin/bash"Log in." Opens a shell inside the container.