根据overlay2目录名找容器
docker ps -q | xargs docker inspect --format '{{.State.Pid}}, {{.Id}}, {{.Name}}, {{.GraphDriver.Data.WorkDir}}'
调试coredns
kubectl run -it --rm --restart=Never --image=infoblox/dnstools:latest dnstools
查看资源使用情况
kubectl get nodes --no-headers | awk '{print $1}' | xargs -I {} sh -c "echo {} ; kubectl describe node {} | grep Allocated -A 5 | grep -ve Event -ve Allocated -ve percent -ve --;"
查看资源总情况
kubectl get no -o=custom-columns="NODE:.metadata.name,ALLOCATABLE CPU:.status.allocatable.cpu,ALLOCATABLE MEMORY:.status.allocatable.memory"
查看CPU分配情况
kubectl get nodes --no-headers | awk '{print $1}' | xargs -I {} sh -c 'echo -n "{}\t" ; kubectl describe node {} | grep Allocated -A 5 | grep -ve Event -ve Allocated -ve percent -ve -- | grep cpu | awk '\''{print $2$3}'\'';'
查看内存分配情况
kubectl get nodes --no-headers | awk '{print $1}' | xargs -I {} sh -c 'echo -n "{}\t" ; kubectl describe node {} | grep Allocated -A 5 | grep -ve Event -ve Allocated -ve percent -ve -- | grep memory | awk '\''{print $2$3}'\'';'
线程数统计
printf " NUM PID\t\tCOMMAND\n" && ps -eLf | awk '{$1=null;$3=null;$4=null;$5=null;$6=null;$7=null;$8=null;$9=null;print}' | sort |uniq -c |sort -rn | head -10
配置默认storageclass
kubectl patch storageclass <your-class-name> -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
查看容器名
kubectl get po calibre-web-76b9bf4d8b-2kc5j -o json | jq -j ".spec.containers[].name"
进入容器namespace
docker ps | grep APP_NAME
docker inspect CONTAINER_ID | grep Pid
nsenter -t PID -n
查找非 running 状态的 Pod
kubectl get pods -A --field-selector=status.phase!=Running | grep -v Complete
获取节点列表及其内存容量
kubectl get no -o json | \
jq -r '.items | sort_by(.status.capacity.memory)[]|[.metadata.name,.status.capacity.memory]| @tsv'
获取每个节点的Pod数量
kubectl get po -o json --all-namespaces | \
jq '.items | group_by(.spec.nodeName) | map({"nodeName": .[0].spec.nodeName, "count": length}) | sort_by(.count)'
获取前一个容器的日志
kubectl -n my-namespace logs my-pod –previous
把Secret复制到其他namespace
kubectl get secrets -o json --namespace namespace-old | \
jq '.items[].metadata.namespace = "namespace-new"' | \
kubectl create-f -
批量删除所有命名空间下某一个状态的所有pod
kubectl get pods --all-namespaces |grep Terminating | awk 'NR>1 {print $1 ,$2}' | xargs -l -t kubectl delete pod --force --grace-period=0 -n $1 $2
kubectl get pods --all-namespaces |grep Evicted | awk 'NR>1 {print $1 ,$2}' | xargs -l -t kubectl delete pod --force --grace-period=0 -n $1 $2
使用kubectl-debug对某一个pod进行转包分析
kubectl-debug pod-name-xxxx -n xxxx --agentless --port-forward
tcpdump -n -vvv -w /tmp/xxx.pcap
相关推荐
评论 抢沙发