kubernetes.cheat 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. % kubernetes, k8s
  2. # Print all contexts
  3. kubectl config get-contexts
  4. # Print current context of kubeconfig
  5. kubectl config current-context
  6. # Set context of kubeconfig
  7. kubectl config use-context <context>
  8. # Print resource documentation
  9. kubectl explain <resource>
  10. # Get nodes (add option '-o wide' for details)
  11. kubectl get nodes
  12. # Get namespaces
  13. kubectl get namespaces
  14. # Get pods from namespace (add option '-o wide' for details)
  15. kubectl get pods -n <namespace>
  16. # Get pods from all namespace (add option '-o wide' for details)
  17. kubectl get pods --all-namespaces
  18. # Get services from namespace
  19. kubectl get services -n <namespace>
  20. # Get details from resource on namespace
  21. kubectl describe <resource>/<name> -n <namespace>
  22. # Print logs from namespace
  23. kubectl logs -f pods/<name> -n <namespace>
  24. # Get deployments
  25. kubectl get deployments -n <namespace>
  26. # Edit deployments
  27. kubectl edit deployment/<name> -n <namespace>
  28. # Drain node in preparation for maintenance
  29. kubectl drain <name>
  30. # Mark node as schedulable
  31. kubectl uncordon <name>
  32. # Mark node as unschedulable
  33. kubectl cordon <name>
  34. # Display resource (cpu/memory/storage) usage
  35. kubectl top <type>
  36. # List the namespaces in the current context
  37. kubens
  38. # Change the active namespace of current context
  39. kubens <namespaces>
  40. # Switch to the previous namespace in this context
  41. kubens -
  42. # Show the current namespace
  43. kubens -c
  44. $ namespaces: kubens --- --headers 1 --column 3