Kubectl Commands with description
Here is a list of essential `kubectl` commands along with their descriptions:
### **Basic Commands**
1. **`kubectl version`**
- Displays the version information of the client and server
2. **`kubectl help`**
- Provides help for any command or subcommand.
3. **`kubectl cluster-info`**
- Shows information about the Kubernetes cluster.
4. **`kubectl get`**
- Retrieves and lists resources.
- **Example:** `kubectl get pods` lists all Pods in the current namespace.
5. **`kubectl describe`**
- Provides detailed information about a specific resource.
- **Example:** `kubectl describe pod <pod-name>` shows detailed info about the specified Pod.
6. **`kubectl create`**
- Creates a resource from a file or from stdin.
- **Example:** `kubectl create -f <filename>.yaml` creates resources defined in a YAML file.
7. **`kubectl apply`**
- Applies a configuration to a resource by filename or stdin.
- **Example:** `kubectl apply -f <filename>.yaml` updates or creates the resources defined in the file.
8. **`kubectl delete`**
- Deletes resources by filenames, stdin, resources, and names.
- **Example:** `kubectl delete pod <pod-name>` deletes the specified Pod.
### **Namespace Commands**
9. **`kubectl get namespaces`**
- Lists all namespaces in the cluster.
10. **`kubectl create namespace <namespace-name>`**
- Creates a new namespace.
11. **`kubectl delete namespace <namespace-name>`**
- Deletes a specific namespace.
12. **`kubectl config set-context --current --namespace=<namespace-name>`**
- Sets the default namespace for the current context.
### **Pod Management**
13. **`kubectl get pods`**
- Lists all Pods in the current namespace.
14. **`kubectl describe pod <pod-name>`**
- Shows detailed information about a specific Pod.
15. **`kubectl logs <pod-name>`**
- Retrieves logs from a specific Pod.
16. **`kubectl exec <pod-name> -- <command>`**
- Executes a command in a container within a Pod.
- **Example:** `kubectl exec <pod-name> -- ls /` runs the `ls` command in the specified Pod.
17. **`kubectl port-forward <pod-name> <local-port>:<pod-port>`**
- Forwards one or more local ports to a Pod.
18. **`kubectl cp <source> <pod-name>:<destination>`**
- Copies files and directories to and from containers.
### **Service Management**
19. **`kubectl get services`**
- Lists all Services in the current namespace.
20. **`kubectl describe service <service-name>`**
- Shows detailed information about a specific Service.
21. **`kubectl expose <resource>`**
- Exposes a resource (e.g., Pod, Deployment) as a new Kubernetes Service.
### **Deployment Management**
22. **`kubectl get deployments`**
- Lists all Deployments in the current namespace.
23. **`kubectl describe deployment <deployment-name>`**
- Shows detailed information about a specific Deployment.
24. **`kubectl scale deployment <deployment-name> --replicas=<number>`**
- Scales a Deployment to the specified number of replicas.
25. **`kubectl rollout status deployment <deployment-name>`**
- Shows the status of the rollout for a Deployment.
26. **`kubectl rollout undo deployment <deployment-name>`**
- Rolls back a Deployment to the previous version.
27. **`kubectl set image deployment/<deployment-name> <container-name>=<new-image>`**
- Updates the image of a container in a Deployment.
### **ConfigMap and Secret Management**
28. **`kubectl get configmaps`**
- Lists all ConfigMaps in the current namespace.
29. **`kubectl create configmap <configmap-name> --from-literal=<key>=<value>`**
- Creates a ConfigMap from literal values.
30. **`kubectl create configmap <configmap-name> --from-file=<path>`**
- Creates a ConfigMap from a file or directory.
31. **`kubectl get secrets`**
- Lists all Secrets in the current namespace.
32. **`kubectl create secret generic <secret-name> --from-literal=<key>=<value>`**
- Creates a Secret from literal values.
33. **`kubectl create secret generic <secret-name> --from-file=<path>`**
- Creates a Secret from a file or directory.
### **Persistent Volume Management**
34. **`kubectl get pv`**
- Lists all PersistentVolumes in the cluster.
35. **`kubectl get pvc`**
- Lists all PersistentVolumeClaims in the current namespace.
36. **`kubectl describe pv <pv-name>`**
- Shows detailed information about a specific PersistentVolume.
37. **`kubectl describe pvc <pvc-name>`**
- Shows detailed information about a specific PersistentVolumeClaim.
### **Labeling and Annotating Resources**
38. **`kubectl label <resource> <name> <key>=<value>`**
- Adds or updates a label on a resource.
39. **`kubectl annotate <resource> <name> <key>=<value>`**
- Adds or updates an annotation on a resource.
### **Resource Management**
40. **`kubectl top pods`**
- Shows the resource usage (CPU/Memory) of Pods.
41. **`kubectl top nodes`**
- Shows the resource usage (CPU/Memory) of Nodes.
### **Role-Based Access Control (RBAC)**
42. **`kubectl get roles`**
- Lists all Roles in the current namespace.
43. **`kubectl get rolebindings`**
- Lists all RoleBindings in the current namespace.
44. **`kubectl create role <role-name> --verb=<verb> --resource=<resource>`**
- Creates a Role with specific permissions.
45. **`kubectl create rolebinding <rolebinding-name> --role=<role-name> --user=<user-name>`**
- Creates a RoleBinding to grant a user permissions in the namespace.
### **Job and CronJob Management**
46. **`kubectl get jobs`**
- Lists all Jobs in the current namespace.
47. **`kubectl get cronjobs`**
- Lists all CronJobs in the current namespace.
48. **`kubectl describe job <job-name>`**
- Shows detailed information about a specific Job.
49. **`kubectl describe cronjob <cronjob-name>`**
- Shows detailed information about a specific CronJob.
### **Troubleshooting**
50. **`kubectl logs <pod-name>`**
- Retrieves logs from a specific Pod.
51. **`kubectl describe <resource> <name>`**
- Shows detailed information about a resource, useful for troubleshooting.
52. **`kubectl exec <pod-name> -- <command>`**
- Executes a command in a container, useful for debugging.
53. **`kubectl get events`**
- Lists recent events in the cluster, useful for debugging issues.
54. **`kubectl run --rm -it --image=<image> <pod-name> -- <command>`**
- Runs a command in a new Pod and removes the Pod after the command finishes.
### **Advanced Commands**
55. **`kubectl apply -k <directory>`**
- Applies resources using a Kustomization directory.
56. **`kubectl edit <resource> <name>`**
- Edits a resource from the default editor.
57. **`kubectl patch <resource> <name> --patch <patch-data>`**
- Updates a resource using a patch.
58. **`kubectl auth can-i <verb> <resource>`**
- Checks whether the user has permission to perform a given action on a resource.
59. **`kubectl proxy`**
- Starts a proxy to the Kubernetes API server.
### **Resource Definition**
60. **`kubectl explain <resource>`**
- Describes the fields of a resource, including definitions and examples.
This list covers most of the essential `kubectl` commands you'll use regularly when working with Kubernetes.
Comments
Post a Comment