Skip to content

Instantly share code, notes, and snippets.

@gotraveltoworld
Last active February 8, 2019 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gotraveltoworld/1ab757c03d1a7262b9b9cf7fcf8fbed9 to your computer and use it in GitHub Desktop.
Save gotraveltoworld/1ab757c03d1a7262b9b9cf7fcf8fbed9 to your computer and use it in GitHub Desktop.
Commom kubectl statements.

Show pods info.

  kubectl get pods

Show all pods.

  kubectl get pods --show-all

Get specify pod's decribe.

  kubectl describe pod <pod>  

Build a service object for outside accessing.

  kubectl expose pod <pod> --port=<port> --name=<service-name>

Port mapping from pod to host.

  kubectl port-forward <pod> <external-port>:<pod-port>

Attach into pod's inside.

  kubectl attach <pod> -i

Execute a command inside the pod.

  kubectl exec <pod> -- <command> 
  # Ex: kubectl exec <pod> -- ls /app

Add Labels

  kubectl label pods <pod> <label-key>=<label-value>

Show Labels

  kubectl get pod --show-labels

debug好用的image(alpine)

由於alpine 提供非常輕量級的 Docker's Image(5-6MB左右)。 適合用來測試Pod內部各個container的狀態,在輸入下方指令後,就可以連線到alpine內部,然後再安裝curl來測試內部容器的連線狀況。

  kubectl run -i --tty alpine --image=alpine --restart=Never -- sh
  # in alpine: (先安裝curl方便測試)
    => apk add --no-cache curl

Port-forward

  kubectl port-forward <pod> <external-port>:<pod-port>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment