Kubectl quick reference
This document acts as a quick reference to kubectl
, listing some of the most common operations.
The examples here only address the most basic approach to these operations. For more options, please refer to the command-line help of kubectl
subcommands, which you can access like this:
kubectl get --help
There is also a more detailed cheatsheet in the official kubernetes documentation.
Inspecting running instances of an application
To list running Pods
:
$ kubectl -n <namespace> get pods
To view details for a Pod
:
$ kubectl -n <namespace> describe pod <pod>
Viewing logs
To access the logs of a running container:
$ kubectl -n <namespace> logs <pod>
Viewing kubernetes events
To see kubernetes events, which can help debugging:
$ kubectl -n <namespace> get events
Container shell
You can get a shell inside a running container:
$ kubectl -n <namespace> exec -it <pod> sh
For more information, click here
Pod port-forwarding
To forward port 5000
on localhost
to port 5001
in the Pod
:
$ kubectl -n <namespace> port-forward <pod> 5000:5001
For more information, click here
This page was last reviewed on 3 September 2024.
It needs to be reviewed again on 3 March 2025
by the page owner #cloud-platform
.
This page was set to be reviewed before 3 March 2025
by the page owner #cloud-platform.
This might mean the content is out of date.