Contexts and Configuration -------------------------- | Command | Description | | --- | --- | | `kubectl config view` | Show the current kubeconfig file | | `kubectl config get-contexts` | List all contexts in the kubeconfig file | | `kubectl config current-context` | Show the current context | | `kubectl config use-context ` | Change the current context | | `kubectl config set-context --namespace=` | Set the namespace for a context | | `kubectl config set-context --cluster=` | Set the cluster for a context | | `kubectl config set-context --user=` | Set the user for a context | | `kubectl config set-context --namespace= --cluster= --user=` | Set all context properties | Cluster Management ------------------ | Command | Description | | --- | --- | | `kubectl cluster-info` | Display addresses of the master and services | | `kubectl get nodes` | List all nodes in the cluster | | `kubectl get pods` | List all pods in the cluster | | `kubectl get services` | List all services in the cluster | | `kubectl get deployments` | List all deployments in the cluster | | `kubectl get namespaces` | List all namespaces in the cluster | | `kubectl get events` | List all events in the cluster | Resource Management ------------------- | Command | Description | | --- | --- | | `kubectl apply -f ` | Apply a configuration file | | `kubectl delete -f ` | Delete a configuration file | | `kubectl get ` | List all resources of a type | | `kubectl describe ` | Describe a resource | | `kubectl edit ` | Edit a resource | | `kubectl exec -it -- ` | Execute a command in a pod | Pod Management -------------- | Command | Description | | --- | --- | | `kubectl run --image=` | Create a new pod | | `kubectl delete pod ` | Delete a pod | | `kubectl get pod ` | Get details of a pod | | `kubectl describe pod ` | Describe a pod | | `kubectl logs ` | Show logs of a pod | | `kubectl exec -it -- /bin/bash` | Execute a command in a pod | | `kubectl cp : ` | Copy files from a pod | | `kubectl top node` | Show metrics for all nodes | | `kubectl top pod` | Show metrics for all pods | | `kubectl top pod ` | Show metrics for a specific pod | Service Management ------------------ | Command | Description | | --- | --- | | `kubectl expose pod --port=444 --target-port=555` | Expose a pod as a service | | `kubectl delete service ` | Delete a service | | `kubectl get service ` | Get details of a service | | `kubectl describe service ` | Describe a service | Deployment Management --------------------- | Command | Description | | --- | --- | | `kubectl create deployment --image=` | Create a new deployment | | `kubectl delete deployment ` | Delete a deployment | | `kubectl get deployment ` | Get details of a deployment | | `kubectl describe deployment ` | Describe a deployment | | `kubectl scale deployment --replicas=3` | Scale a deployment to 3 replicas | | `kubectl rollout status deployment/` | Check the status of a deployment rollout | | `kubectl rollout history deployment/` | Show the history of a deployment rollout | | `kubectl rollout undo deployment/` | Rollback a deployment to the previous version | | `kubectl rollout undo deployment/ --to-revision=1` | Rollback a deployment to a specific revision | Namespace Management -------------------- | Command | Description | | --- | --- | | `kubectl create namespace ` | Create a new namespace | | `kubectl delete namespace ` | Delete a namespace | | `kubectl get namespace ` | Get details of a namespace | | `kubectl describe namespace ` | Describe a namespace |