https://www.youtube.com/c/techworld-with-nana
Certainly! Here are 50 commonly used Kubernetes (K8s) commands along with brief explanations for each:
-
kubectl create deployment <name> --image=<image>
: Create a deployment using a specified container image. -
kubectl get pods
: List all pods in the current namespace. -
kubectl describe pod <pod-name>
: Show detailed information about a specific pod. -
kubectl get svc
: List all services in the current namespace. -
kubectl expose deployment <name> --port=<port>
: Create a new service and expose it. -
kubectl scale deployment <name> --replicas=<count>
: Scale the number of replicas for a deployment. -
kubectl get nodes
: List all nodes in the cluster. -
kubectl get deployments
: List all deployments in the current namespace. -
kubectl get configmaps
: List all config maps in the current namespace. -
kubectl get secrets
: List all secrets in the current namespace. -
kubectl create configmap <name> --from-file=<path/to/file>
: Create a config map from a file. -
kubectl create secret generic <name> --from-literal=<key>=<value>
: Create a secret with a literal value. -
kubectl apply -f <yaml-file>
: Apply a configuration file to create or update resources. -
kubectl delete <resource> <name>
: Delete a specific resource. -
kubectl get ingress
: List all ingresses in the current namespace. -
kubectl describe ingress <name>
: Show detailed information about a specific ingress. -
kubectl logs <pod-name>
: View the logs of a specific pod. -
kubectl exec -it <pod-name> -- /bin/bash
: Start an interactive shell in a pod. -
kubectl get namespaces
: List all namespaces in the cluster. -
kubectl create namespace <name>
: Create a new namespace. -
kubectl delete namespace <name>
: Delete a namespace and all its resources. -
kubectl get events
: List cluster events. -
kubectl rollout status deployment/<name>
: Check the status of a deployment rollout. -
kubectl rollout history deployment/<name>
: View rollout history for a deployment. -
kubectl edit <resource> <name>
: Edit a resource using the default editor. -
kubectl apply -f <url>
: Apply a configuration file from a URL. -
kubectl get pods -n <namespace>
: List pods in a specific namespace. -
kubectl exec -it <pod-name> -n <namespace> -- /bin/bash
: Start an interactive shell in a pod in a specific namespace. -
kubectl port-forward <pod-name> <local-port>:<remote-port>
: Forward ports from a pod to your local machine. -
kubectl label <resource> <name> <key>=<value>
: Add a label to a resource. -
kubectl annotate <resource> <name> <key>=<value>
: Add an annotation to a resource. -
kubectl get componentstatuses
: List the health of various cluster components. -
kubectl get pods -o wide
: List pods with additional information, including node names. -
kubectl describe node <node-name>
: Show detailed information about a specific node. -
kubectl get pvc
: List all persistent volume claims. -
kubectl get pv
: List all persistent volumes. -
kubectl delete pvc <pvc-name>
: Delete a persistent volume claim. -
kubectl apply -f <directory>
: Apply all configuration files in a directory. -
kubectl top pods
: Show CPU and memory usage of pods. -
kubectl rollout restart deployment/<name>
: Restart a deployment. -
kubectl apply -f <yaml-file> --dry-run=client
: Check a configuration file for syntax errors without applying it. -
kubectl describe service <service-name>
: Show detailed information about a service. -
kubectl get endpoints
: List endpoints for services. -
kubectl taint nodes <node-name> <key>=<value>:<effect>
: Add a taint to a node. -
kubectl uncordon <node-name>
: Remove a node from "cordoned" state. -
kubectl create role <name> --resource=<resource> --verb=<verb>
: Create a role. -
kubectl create rolebinding <name> --role=<role> --user=<user>
: Create a role binding. -
kubectl drain <node-name>
: Safely evict all pods from a node. -
kubectl apply -f <yaml-file> --validate=false
: Apply a configuration file, skipping validation. -
kubectl proxy
: Start a proxy to access the Kubernetes API.
These commands cover a wide range of common Kubernetes operations. Be sure to replace <name>
, <image>
, <pod-name>
, <port>
, <resource>
, <yaml-file>
, <key>
, <value>
, <url>
, <namespace>
, <local-port>
, <remote-port>
, <node-name>
, <pvc-name>
, <service-name>
, <role>
, <user>
, <effect>
, and <directory>
with appropriate values as needed in your environment.