Kubernetes学习笔记(一)
参考 kubectl Cheat Sheet | Kubernetes
[k8s系统情况]
1) kubernetes config指令:
>kubectl config view # Show Merged kubeconfig settings
>kubectl config get-contexts # display list of contexts
>kubectl config current-context # display the current-context
2) API resource指令:
>kubectl api-resources # for a complete list of supported resources
>kubectl api-resources --verbs=list,get # All resources that support the "list" and "get" request verbs
3)
>kubectl describe
>kubectl explain pods #Get the documentation of the resource and its fields
>kubectl explain pods.spec.containers #JSONPath identifier
>kubectl get node -o wide #output带wide参数,获取详细信息,含node ip地址信息
>kubectl get nodes --show-labels #含failure domain信息
>kubectl cluster-info
>kubectl get apiservices
>kubectl diff -f
[查看各种resource]
1) Get commands with basic output:
>kubectl get services -n
>kubectl get pods --all-namespaces # List all pods in all namespaces
>kubectl get pods -A # List all pods in all namespaces
>kubectl get deployment my-dep # List a particular deployment
2) Describe commands with verbose output:
>kubectl describe nodes my-node
>kubectl describe pods my-pod #包含详细信息,Events项会提供重要信息
[查看pod信息]
>kubectl get pods -o name -A #output,显示name
>kubectl get pods -o wide #output,显示详细信息,含pod的IP地址
>kubectl get pod -n
>kubectl get pod
>kubectl get pods --show-labels #Show labels for all pods (or any other Kubernetes object that supports labelling)
>kubectl get pods -L app #output,显示Label信息
>kubectl get pods -L label1 -L label2
>kubectl get pods -l app #selector过滤
>kubectl get pods -A #获取所有namespace的pods
>kubectl get pods --sort-by='.status.containerStatuses[0].restartCount' # List pods Sorted by Restart Count???
>kubectl get pod my-con --template="{{range .status.containerStatuses}}{{.name}}:{{.restartCount}}{{end}}" #查看某个pod的每个container的重启次数
>kubectl get pods --field-selector=status.phase=Running # Get all running pods in the namespace
>kubectl get pod mysql --template="{{.status.phase}}" #查看pod生命周期
>kubectl get pods --all-namespaces -o jsonpath='{range.items[*].status.initContainerStatuses[*]}{.containerID}{"\n"}{end}' | cut -d/ -f3
# List all containerIDs of initContainer of all pods
# Helpful when cleaning up stopped containers, while avoiding removal of initContainers.
>kubectl exec
>kubectl exec