# check kubernetes inner ip kubectl get svc kubernetes -n default # check api server kubectl get componentstatuses # check crd kubectl get crd | grep cert-manager # check all pods kubectl get pods -A
namespace
1 2 3 4 5 6 7
kubectl get namespaces
# delete all resource by specify namespace kubectl delete all --all -n <namespace>
kubectl get pod <容器id> --kubeconfig=/path/to/configfile -o yaml > env-vq48.yaml # kubectl get -o yaml 这样的参数,会将指定的 Pod API 对象以 YAML 的方式展示出来。 # expose kubectl get pod <pod-name> -n <namespace> -o yaml > pod-config.yaml
exec
without kubeconfig
1 2 3 4 5 6
# enter pod on specify container kubectl exec -it {pod_id} -n {namespace} -c {container_id} -- sh # execute specify command on pod kubectl exec -it {pod_id} -n {namespace} -c {container_id} -- <shell> e.g. kubectl exec -it csi-node-1 -n dingofs -- cat /etc/resolv.conf
copy
1 2 3 4 5 6
kubectl cp 命令空间/容器id:path/to/source_file ./path/to/local_file # 注意 pod里面的路径无需带 /,使用相对路径即可(相对于进入pod之后的默认目录) # kubectl exec -n <namespace> <pod_name> -- tar cf - <path/to/file> | tar xf - -C . # e.g. kubectl exec -n dingofs dingofs-csi-node-5bfkf -- tar cf - /proc/mounts | tar xf - -C .
delete
1 2 3 4 5 6 7 8 9
# method 1 kubectl delete pod {pod_name} --grace-period=0 --force -n {namespace} # method 2 kubectl patch pod <pod-name> -n <target-namespace> -p '{"metadata":{"finalizers":null}}' --type=merge # method 3 step1 : kubectl edit pod <pod-name> -n <namespace> step2 : delete the finalizers array under metadata, save the file, and exit
# list role kubectl get role -n <namespace> # -o yaml # list clusterrole kubectl get clusterrole # list RoleBinding kubectl get rolebinding -n <namespace> # list clusterrolebinding kubectl get clusterrolebinding # Check if the User Can List Pods in Namespace kubectl auth can-i list pods --as=<userName> -n <namespace> # Check If the ServiceAccount Has Permissions to Get DaemonSets kubectl auth can-i get daemonsets --as=system:serviceaccount:<namespace>:<serviceAccount> -n <namespace>
secret
1 2 3
# check raw info kubectl get secret <secret-name> -o jsonpath="{.data.<key>}" | base64 -d