less than 1 minute read

Tags: ,

kubectl Cheat Sheet

kubectl config

Modify kubeconfig files using subcommands like “kubectl config set current-context my-context”

  • 看當前的 context
    • kubectl config current-context

Viewing, finding resources

  # Get commands with basic output
  kubectl get services                          # List all services in the namespace
  kubectl get pods --all-namespaces             # List all pods in all namespaces
  kubectl get pods -o wide                      # List all pods in the current namespace, with more details
  kubectl get deployment my-dep                 # List a particular deployment
  kubectl get pods                              # List all pods in the namespace
  kubectl get pod my-pod -o yaml                # Get a pod's YAML
  
  # Describe commands with verbose output
  kubectl describe nodes my-node
  kubectl describe pods my-pod
  
  # List Services Sorted by Name
  kubectl get services --sort-by=.metadata.name