K8s Commands
K8s Commands
Nodes:
List all nodes in the cluster.
$kubectl get nodes
Show detailed information about a node.
$kubectl describe node <node-name>
Pods:
List all pods in the current namespace.
$kubectl get pods
Show detailed information about a pod.
$kubectl describe pod <pod-name>
Print the logs from a pod.
$kubectl logs <pod-name>
Access a shell inside a running pod.
$kubectl exec -it <pod-name> -- /bin/sh
Deployments:
List all deployments.
$kubectl get deployments
Show detailed information about a deployment.
$kubectl describe deployment <deployment-name>
Scale the number of replicas in a deployment.
$kubectl scale deployment <deployment-name> --replicas=<num>
Services:
List all services in the current namespace.
$kubectl get services
Show detailed information about a service.
$kubectl describe service <service-name>
1
ConfigMaps and Secrets:
List all ConfigMaps.
$kubectl get configmaps
List all secrets.
$kubectl get secrets
Namespaces:
List all namespaces.
$kubectl get namespaces
Create a new namespace.
$kubectl create namespace <namespace-name>
Contexts:
List all contexts.
$kubectl config get-contexts
Set the current context.
$kubectl config use-context <context-name>
2
Add a label to a pod.
$kubectl label pod <pod-name> <key>=<value>
Deleting Resources:
Delete a pod.
$kubectl delete pod <pod-name>
Delete a deployment.
$kubectl delete deployment <deployment-name>
Delete a service.
$kubectl delete service <service-name>