Kubectl
kubectl
Syntax
Use the following syntax to run kubectl commands from your terminal window:
kubectl [command] [TYPE] [NAME] [flags]
Where command,TYPE,NAME,flags are:
command: Specifies the operation that you want to perform on one or more resources.TYPE: Specifies the resources type.NAME: Specifies the name of the resources.flags: Specifies optional flags.
Operations
| Description | Docker | Kubectl |
|---|---|---|
| List containers/pods | docker ps [-a] |
kubectl get pods [-A] |
| Detect logs | docker logs <container_id> |
kubectl logs <pod_name> |
| Run a container/pod | docker run <image> |
kubectl run <name> --image=<image> |
| Stop/delete a container/pod | docker stop <container_id> |
kubectl delete pod <pod_name> |
| Remove a stopped container | docker rm <container_id> |
(Not directly applicable) |
| List images | docker images |
kubectl get pods -o=jsonpath='{..image}'(It does not work for me) |
| Pull an image | docker pull <image> |
(Not directly applicable. Images are pulled when deploying a pod) |
| Execute a command in a container | docker exec -it <container_id> /bin/sh |
kubectl exec -it <pod_name> -- /bin/sh |
| Build an image from a Dockerfile | docker build . -t <tag> |
(Not directly applicable) |
| List networks | docker network ls |
kubectl get services |
| List volumes | docker volume ls |
kubectl get pv |
| Create a volume | docker volume create |
kubectl apply -f <pv_config.yaml> |