k8s常用命令操作

获取所有节点的污点信息

kubectl get nodes -o='custom-columns=NodeName:.metadata.name,TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect'

获取集群内的所有域名

kubectl get ingress -A -o=custom-columns=Host:.spec.rules[*].host |grep -v none |sed 's/,/\n/g' |sort -n |uniq |sort |grep -v Host

获取配置了证书的域名

kubectl get ingress -A -o=custom-columns=Tls:.spec.tls[*].hosts[0] |grep -v none |sed 's/,/\n/g' |sort -n |uniq |sort |grep -v Tls

筛选运行异常的POD

kubectl get pod -A --field-selector='status.phase==Failed' --output=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace,STATUS:.status.phase,AGE:'.metadata.creationTimestamp'
# 获取异常状态超过2天的POD
kubectl get pod -A --field-selector='status.phase==Failed' --output=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace,STATUS:.status.phase,AGE:'.metadata.creationTimestamp'| awk '$4 <= "'$(date -d '2 days ago' -Ins --utc | sed 's/+0000/Z/')'"

k8s查看pod的网络是否为hostNetwork

kubectl get pod <pod-name> -o jsonpath='{.spec.hostNetwork}'

k8s获取secrets的配置并进行解码

kubectl get secret my-secret -o 'go-template={{index .data "username"}}' | base64 -d
posted @ 2023-12-29 14:12  yuhaohao  阅读(31)  评论(0编辑  收藏  举报