100 useful Kubernetes commands

 Here is a list of 100 useful Kubernetes commands:


1. kubectl get pods: List all pods in the current namespace

2. kubectl get deployments: List all deployments in the current namespace

3. kubectl get services: List all services in the current namespace

4. kubectl get nodes: List all nodes in the cluster

5. kubectl get namespaces: List all namespaces in the cluster

6. kubectl describe pod [pod-name]: Get detailed information about a specific pod

7. kubectl describe deployment [deployment-name]: Get detailed information about a specific deployment

8. kubectl describe service [service-name]: Get detailed information about a specific service

9. kubectl describe node [node-name]: Get detailed information about a specific node

10. kubectl describe namespace [namespace-name]: Get detailed information about a specific namespace

11. kubectl create deployment [deployment-name] --image=[image-name]: Create a new deployment using a specific image

12. kubectl delete pod [pod-name]: Delete a specific pod

13. kubectl delete deployment [deployment-name]: Delete a specific deployment

14. kubectl delete service [service-name]: Delete a specific service

15. kubectl delete node [node-name]: Delete a specific node

16. kubectl delete namespace [namespace-name]: Delete a specific namespace

17. kubectl apply -f [filename]: Apply a configuration file to create or update Kubernetes resources

18. kubectl exec -it [pod-name] -- [command]: Execute a command in a specific pod

19. kubectl logs [pod-name]: View the logs of a specific pod

20. kubectl port-forward [pod-name] [local-port]:[remote-port]: Forward a local port to a port on a specific pod

21. kubectl scale deployment [deployment-name] --replicas=[number]: Scale the number of replicas for a specific deployment

22. kubectl expose deployment [deployment-name] --port=[port] --target-port=[target-port]: Expose a deployment as a service

23. kubectl label pod [pod-name] [label-key]=[label-value]: Add a label to a specific pod

24. kubectl label deployment [deployment-name] [label-key]=[label-value]: Add a label to a specific deployment

25. kubectl annotate pod [pod-name] [annotation-key]=[annotation-value]: Add an annotation to a specific pod

26. kubectl annotate deployment [deployment-name] [annotation-key]=[annotation-value]: Add an annotation to a specific deployment

27. kubectl get pod [pod-name] -o yaml: Get the YAML definition of a specific pod

28. kubectl get deployment [deployment-name] -o yaml: Get the YAML definition of a specific deployment

29. kubectl get service [service-name] -o yaml: Get the YAML definition of a specific service

30. kubectl get node [node-name] -o yaml: Get the YAML definition of a specific node

31. kubectl get namespace [namespace-name] -o yaml: Get the YAML definition of a specific namespace

32. kubectl edit pod [pod-name]: Edit the configuration of a specific pod

33. kubectl edit deployment [deployment-name]: Edit the configuration of a specific deployment

34. kubectl edit service [service-name]: Edit the configuration of a specific service

35. kubectl edit node [node-name]: Edit the configuration of a specific node

36. kubectl edit namespace [namespace-name]: Edit the configuration of a specific namespace

37. kubectl rollout status deployment [deployment-name]: Check the status of a deployment rollout

38. kubectl rollout history deployment [deployment-name]: View the revision history of a deployment

39. k


ubectl rollout undo deployment [deployment-name]: Rollback a deployment to a previous revision

40. kubectl scale deployment [deployment-name] --replicas=[number]: Scale the number of replicas for a specific deployment

41. kubectl autoscale deployment [deployment-name] --min=[min-replicas] --max=[max-replicas] --cpu-percent=[cpu-percent]: Autoscale a deployment based on CPU usage

42. kubectl create secret generic [secret-name] --from-literal=[key]=[value]: Create a secret with a key-value pair

43. kubectl create configmap [configmap-name] --from-literal=[key]=[value]: Create a configmap with a key-value pair

44. kubectl rollout pause deployment [deployment-name]: Pause a deployment rollout

45. kubectl rollout resume deployment [deployment-name]: Resume a paused deployment rollout

46. kubectl apply -f [directory]: Apply all configuration files in a specific directory

47. kubectl apply -f [url]: Apply a configuration file from a URL

48. kubectl get all: List all resources (pods, deployments, services, etc.) in the current namespace

49. kubectl delete all --all: Delete all resources in the current namespace

50. kubectl explain [resource]: Get documentation about a specific Kubernetes resource


51. kubectl top pod: Display resource usage (CPU and memory) for pods

52. kubectl top node: Display resource usage (CPU and memory) for nodes

53. kubectl rollout restart deployment [deployment-name]: Restart a deployment by triggering a rollout

54. kubectl rollout restart statefulset [statefulset-name]: Restart a statefulset by triggering a rollout

55. kubectl rollout restart daemonset [daemonset-name]: Restart a daemonset by triggering a rollout

56. kubectl rollout restart deployment [deployment-name] --namespace=[namespace]: Restart a deployment in a specific namespace

57. kubectl rollout restart statefulset [statefulset-name] --namespace=[namespace]: Restart a statefulset in a specific namespace

58. kubectl rollout restart daemonset [daemonset-name] --namespace=[namespace]: Restart a daemonset in a specific namespace

59. kubectl attach [pod-name]: Attach to a specific pod's console

60. kubectl top pod [pod-name]: Display resource usage (CPU and memory) for a specific pod

61. kubectl top node [node-name]: Display resource usage (CPU and memory) for a specific node

62. kubectl rollout history deployment [deployment-name] --revision=[revision]: View details about a specific revision of a deployment

63. kubectl rollout undo deployment [deployment-name] --to-revision=[revision]: Rollback a deployment to a specific revision

64. kubectl exec -it [pod-name] --container=[container-name] -- [command]: Execute a command in a specific container of a pod

65. kubectl logs [pod-name] --container=[container-name]: View the logs of a specific container in a pod

66. kubectl exec -it [pod-name] -c [container-name] -- [command]: Execute a command in a specific container of a pod

67. kubectl logs [pod-name] -c [container-name]: View the logs of a specific container in a pod

68. kubectl rollout pause deployment [deployment-name] --namespace=[namespace]: Pause a deployment rollout in a specific namespace

69. kubectl rollout resume deployment [deployment-name] --namespace=[namespace]: Resume a paused deployment rollout in a specific namespace

70. kubectl rollout status deployment [deployment-name] --namespace=[namespace]: Check the status of a deployment rollout in a specific namespace



71. kubectl rollout history deployment [deployment-name] --namespace=[namespace]: View the revision history of a deployment in a specific namespace

72. kubectl rollout undo deployment [deployment-name] --to-revision=[revision] --namespace=[namespace]: Rollback a deployment to a specific revision in a specific namespace

73. kubectl get pods --all-namespaces: List all pods in all namespaces

74. kubectl get deployments --all-namespaces: List all deployments in all namespaces

75. kubectl get services --all-namespaces: List all services in all namespaces

76. kubectl get nodes --all-namespaces: List all nodes in all namespaces

77. kubectl get namespaces --all-namespaces: List all namespaces in the cluster

78. kubectl describe pod [pod-name] --namespace=[namespace]: Get detailed information about a specific pod in a specific namespace

79. kubectl describe deployment [deployment-name] --namespace=[namespace]: Get detailed information about a specific deployment in a specific namespace

80. kubectl describe service [service-name] --namespace=[namespace]: Get detailed information about a specific service in a specific namespace

81. kubectl describe node [node-name] --namespace=[namespace]: Get detailed information about a specific node in a specific namespace

82. kubectl describe namespace [namespace-name] --namespace=[namespace]: Get detailed information about a specific namespace in a specific namespace

83. kubectl create deployment [deployment-name] --image=[image-name] --namespace=[namespace]: Create a new deployment in a specific namespace using a specific image

84. kubectl delete pod [pod-name] --namespace=[namespace]: Delete a specific pod in a specific namespace

85. kubectl delete deployment [deployment-name] --namespace=[namespace]: Delete a specific deployment in a specific namespace

86. kubectl delete service [service-name] --namespace=[namespace]: Delete a specific service in a specific namespace

87. kubectl delete node [node-name] --namespace=[namespace]: Delete a specific node in a specific namespace

88. kubectl delete namespace [namespace-name] --namespace=[namespace]: Delete a specific namespace in a specific namespace

89. kubectl apply -f [filename] --namespace=[namespace]: Apply a configuration file to create or update Kubernetes resources in a specific namespace

90. kubectl exec -it [pod-name] --container=[container-name] --namespace=[namespace] -- [command]: Execute a command in a specific container of a pod in a specific namespace

91. kubectl logs [pod-name] --container=[container-name] --namespace=[namespace]: View the logs of a specific container in a pod in a specific namespace

92. kubectl port-forward [pod-name] [local-port]:[remote-port] --namespace=[namespace]: Forward a local port to a port on a specific pod in a specific namespace

93. kubectl scale deployment [deployment-name] --replicas=[number] --namespace=[namespace]: Scale the number of replicas for a specific deployment in a specific namespace

94. kubectl expose deployment [deployment-name] --port=[port] --target-port=[target-port] --namespace=[namespace]: Expose a deployment as a service in a specific namespace

95. kubectl label pod [pod-name] [label-key]=[label-value] --namespace=[namespace]: Add a label to a specific pod in a specific namespace

96. kubectl label deployment [deployment-name] [label-key]=[label-value] --namespace=[namespace]: Add a label to a specific deployment in a specific namespace

97. kubectl annotate pod [pod-name] [annotation-key]=[annotation-value] --namespace=[namespace]: Add an annotation to a specific pod in a specific namespace

98. kubectl


 annotate deployment [deployment-name] [annotation-key]=[annotation-value] --namespace=[namespace]: Add an annotation to a specific deployment in a specific namespace

99. kubectl get pod [pod-name] -o yaml --namespace=[namespace]: Get the YAML definition of a specific pod in a specific namespace

100. kubectl get deployment [deployment-name] -o yaml --namespace=[namespace]: Get the YAML definition of a specific deployment in a specific namespace


Please note that the above list includes commonly used Kubernetes commands, but it's not an exhaustive list. There are many more commands and options available in Kubernetes, and you can refer to the official Kubernetes documentation for a comprehensive list of commands and their usage.

No comments:

Post a Comment

Featured Post

H1B Visa Stamping at US Consulate

  H1B Visa Stamping at US Consulate If you are outside of the US, you need to apply for US Visa at a US Consulate or a US Embassy and get H1...