Essential kubectl Commands
Duration: 5 min read
Official documentation for kubectl
List a Resource from the API Server
To retrieve details of a specific resource in Kubernetes, use the following command:
Describe a Resource from the API Server
To get a detailed description of a specific resource, use:
Create or Update Resources from a File
To create or update resources from a YAML file, use:
Delete Resources from a File
To delete resources defined in a YAML file, use:
Edit a Resource in the Kubernetes Database (i.e., etcd)
To edit a resource directly in the Kubernetes database, use:
Display Inline Documentation (and Provide Useful Examples)
To display help and usage examples for a specific command, use:
Describe YAML Specification
To get a description of the YAML specification for a specific resource type, use:
Display Logs for a Container (i.e., stdout/stderr)
To display logs from a specific container, use:
Open an Interactive Shell Inside a Container
To open an interactive shell inside a container, use:
Provide Network Access to a Pod
To listen on port 8080 locally and forward data to/from port 80 in the pod, use:
Quickly Generate a YAML Specification
The --dry-run=client -o yaml options allow you to generate YAML without creating the resource in Kubernetes. They are very useful for quickly generating YAML files that can serve as a working base. Here is an example of its usage:
See List of Resources in Use
This command requires the installation of ‘kubernetes-sigs/metrics-server’. To display metrics for nodes and pods, use:
Copy Files To and From a Container
To copy files to and from a container, use: