Snippets: Kubernetes: kubectl

 20th August 2020 at 2:19pm

Context

kubectl config set-context onlyice --namespace=main
kubectl config get-contexts
kubectl config use-context onlyice

Viewing, Finding Resources

如果你在 context 中指定了 namespace,则下面的命名中 -n 参数可以不带。

# get all pods
kubectl get pods -n <namespace>
# describe all pods
kubectl describe pods -n <namespace>

Get Running Container Shell

# get pod name
kubectl get pods
# get detail infomation about specific pods including containers
kubectl describe pod/<pod_name> -n <namespace>
# get a shell to the container
kubectl exec -it <pod_name> -c <container_name> -- sh

参考:Get a Shell to a Running Container

参考