| sidebar_position |
3 |
| title |
Kubernetes Commands |
| description |
A collection of commands to help you with Kubernetes. |
| tags |
Kubernetes |
Containerization |
DevOps |
|
| keywords |
Kubernetes |
Containerization |
DevOps |
|
| slug |
/kubernetes/commands |
kubectl version
kubectl version --output=yaml
- To check info about the cluster
kubectl run <pod name> --image <image name>
kubectl run mynginx --image nginx
kubectl create deployment <name> --image <image name>
kubectl create deployment mynginx --image nginx
- To scale the deployment (increase replicas)
kubectl scale deployment <deployment name> --replicas <no of replicas>
kubectl scale deployment mynginx --replicas 2
- To check all running services, pods, etc.
- To get details from a particular namespace
kubectl get all -n <namespace name>
- To get the internal components running
kubectl get pods -A
kubectl get pods -A -owide
- To check all the running services
- To check all the running pods
// with extra details
kubectl get pods -o wide
- To check all the running nodes
- To check all the namespaces
- To get all the API resources
kubectl delete deployment <deployment-name>
kubectl delete pod <pod-name>
kubectl delete pod --field-selector="status.phase==Failed"
- To open a shell in a specific container or inspect logs in a multi-container Pod
kubectl exec -it <pod-name> -c <container-name> -- <bash command>
kubectl exec -it multi-container -c nginx-container -- curl localhost
kubectl exec -it multi-container -c nginx-container -- sh
kubectl logs multi-container -c nginx-container
kubectl exec -it <pod name> -- sh
kubectl exec -it nginx -- sh
- Get detailed state and event changes for a Pod
kubectl describe pod <pod-name>
- To watch the pods (watch refresh every few seconds)
- To check the available cluster contexts
kubectl config get-contexts
- We can create namespace by
kubectl create namespace <name>
kubectl create namespace dev
- To do a dry run and get the output as YAML
kubectl create namespace test-name --dry-run=client -oyaml
- To edit the deployment (deployment file)
kubectl edit deployment <deployment name>
kubectl delete pods --all
- Apply to a particular namespace
kubectl apply -f <config file name> --namespace=<namespace name>
- Get all the PersistentVolume
- Get all the PersistentVolumeClaim (tied to a namespace)
- To change the default or active namespace
kubectl config set-context --current --namespace=<namespace name>
- To get the details of a particular namespace
kubectl get all -n <namespace name>