π Cheat Sheet - Kubernetes Goat
Below are some commonly useful commands to navigate around Kubernetes, docker, and in general Kubernetes Goat project.
π³ Dockerβ
- To get the docker version
docker version
- To list the running docker containers. To see with all the different states you can add an option
-a
flag
docker ps
- To list the available docker images
docker images
- To run a simple alpine container and exec into it
docker run -it alpine sh
- To show the containers, system, images, and other information
docker info
- To exec into an existing running container
docker exec -it <CONTAINER NAME> sh
- To inspect a container or image
docker inspect <CONTAINER NAME>
docker inspect <IMAGE NAME>
- Search through all public available images in docker hub via CLI command
docker search nginx
βΈοΈ Kubernetesβ
- To get the Kubernetes server version
kubectl version
- To get Kubernetes cluster information
kubectl cluster-info
- To get node information
kubectl get nodes
- To get pods details in the current namespace
kubectl get pods
tip
To get similarly other resources information like services, namespaces, deployments, ingress, secrets, etc. Also, we can use shorthand notation as mentioned below rather than specifying the full name of the resource
kubectl get svc
kubectl get ing
kubectl get ns
kubectl get deploy
kubectl get secrets
- To get more detailed information on the resource
kubectl get pods -o wide
- Information of the resource with descriptively
kubectl describe pod <PODNAME>
- To get a shell inside the pod container
kubectl exec -it <PODNAME> sh
- Creating simple deployment using the command line
kubectl run nginxdeployment --image=nginx
- To forward the pod port from Kubernetes to locally using the built-in command
kubectl port-forward <PODNAME> 1234:80
- To get the logs of the pod/container
kubectl logs <PODNAME>
kubectl logs -f <PODNAME>
- To delete the pod from the cluster
kubectl delete pod <PODNAME>
- Get resources from other namespaces by specifying the namespace name
abc
kubectl get pods -n abc
- To get all the available API resources
kubectl api-resources
- Impersonate the users and get the permission to verify and validate using
kubectl
kubectl auth can-i create pods
- To get any resource output in YAML format
kubectl get pod <POD NAME> -o yaml
- To get multiple commands output in the same command
kubectl get nodes,pods,svc