+--------------------+
| |
| kubectl CLI |
| |
+---------+----------+
|
|
|
v
+-----------------+-----------------+
| |
| Master Node |
| |
+--------+---------+--------+-------+
| | |
| | |
| | |
v v v
+--------+---+ +---+--------+--------+
| | | | |
| API Server | | Scheduler| etcd |
| | | | |
+-----+------+ +---+------+---+------+
| | |
v | |
+---------+------+ | |
| | | |
| Controller | | |
| Manager | | |
+----------------+ | |
| |
v v
+---+-------+---+
| |
| etcd |
| |
+---+-------+---+
| |
v v
+-------+-------+-------+
| |
| Worker Nodes |
| |
+---------+-------------+
|
v
+---------------+---------------+
| |
| |
v v
+----------------+-----------+ +--------------+-----------+
| Kubelet | | Kubelet |
| Container Runtime | | Container Runtime |
+----------------+-----------+ +--------------+-----------+
| |
v v
+----------------+-----------+ +--------------+-----------+
| Pods | | Pods |
| | | |
+-----------------------------+ +---------------------------+
Command | Explanation |
---|---|
kubectl get nodes |
Lists all nodes in the cluster, showing their status, roles, and other details. |
kubectl get pods |
Lists all pods in the current namespace. |
kubectl get pods --all-namespaces |
Lists all pods across all namespaces. |
kubectl get services |
Lists all services in the current namespace. |
kubectl get deployments |
Lists all deployments in the current namespace. |
kubectl get replicasets |
Lists all replicasets in the current namespace. |
kubectl get statefulsets |
Lists all statefulsets in the current namespace. |
kubectl get daemonsets |
Lists all daemonsets in the current namespace. |
kubectl describe node <node-name> |
Provides detailed information about a specific node. |
kubectl describe pod <pod-name> |
Provides detailed information about a specific pod. |
kubectl create -f <file.yaml> |
Creates resources defined in a YAML file. |
kubectl apply -f <file.yaml> |
Applies changes defined in a YAML file to existing resources or creates them if they don't exist. |
kubectl delete pod <pod-name> |
Deletes a specific pod. |
kubectl delete -f <file.yaml> |
Deletes resources defined in a YAML file. |
kubectl delete service <service-name> |
Deletes a specific service. |
kubectl delete deployment <deployment-name> |
Deletes a specific deployment. |
kubectl logs <pod-name> |
Fetches the logs for a specific pod. |
kubectl logs <pod-name> -c <container-name> |
Fetches the logs for a specific container within a pod. |
kubectl exec -it <pod-name> -- <cmd> |
Executes a command in a running pod, with interactive terminal. |
kubectl port-forward <pod-name> <local-port>:<pod-port> |
Forwards a port from a pod to the local machine. |
kubectl scale --replicas=<num> deployment/<deployment-name> |
Scales a deployment to the specified number of replicas. |
kubectl rollout status deployment/<deployment-name> |
Checks the status of a deployment rollout. |
kubectl rollout undo deployment/<deployment-name> |
Rolls back a deployment to a previous revision. |
kubectl set image deployment/<deployment-name> <container-name>=<new-image> |
Updates the image of a container in a deployment. |
kubectl get namespaces |
Lists all namespaces in the cluster. |
kubectl get events |
Lists events in the current namespace, showing recent activity. |
kubectl config get-contexts |
Lists all available contexts in the kubeconfig file. |
kubectl config use-context <context> |
Switches to a different context in the kubeconfig file. |
kubectl top node |
Displays resource usage (CPU/memory) of nodes. |
kubectl top pod |
Displays resource usage (CPU/memory) of pods. |
kubectl apply --record -f <file.yaml> |
Records the current command in the resource's annotation for future rollbacks. |
kubectl annotate <resource> <name> <key>=<value> |
Adds or updates an annotation on a resource. |
kubectl label <resource> <name> <key>=<value> |
Adds or updates a label on a resource. |
kubectl edit <resource> <name> |
Edits a resource on the server directly. |
kubectl patch <resource> <name> --patch <patch-data> |
Updates a resource using a JSON patch. |
kubectl cp <source> <pod-name>:<destination> |
Copies a file from local machine to a pod. |
kubectl taint nodes <node-name> <key>=<value>:<effect> |
Taints a node to control which pods can be scheduled on it. |