快速导航
pod
查看对外开放pod和port
1kubectl get svc --all-namespaces | grep -v ClusterIP
1kubectl get svc --all-namespaces -o go-template='{{range .items}}{{ $save := . }}{{range.spec.ports}}{{if .nodePort}}{{$save.metadata.namespace}}{{"/"}}{{$save.metadata.name}}{{" - "}}{{.name}}{{": "}}{{.nodePort}}{{"\n"}}{{end}}{{end}}{{end}}'
清理所有状态为Failed或者Evicted的pod
1#!/bin/bash
2kubectl get pods --all-namespaces -o go-template='{{range .items}} \
3{{if eq .status.phase "Failed"}} {{if eq .status.reason "Evicted"}} {{.metadata.name}}{{" "}} {{.metadata.namespace}}{{"\n"}} \
4{{end}} \
5{{end}} \
6{{end}}' | while read epod namespace; do kubectl -n $namespace delete pod $epod; done
查看pod id
1kubectl get pods --all-namespaces -o custom-columns=PodName:.metadata.name,PodUID:.metadata.uid,NODE:.spec.nodeName
查看pod所在节点
1kubectl get pod -o wide --all-namespaces
2# 或者
3kubectl get pod -o=custom-columns=NODE:.spec.nodeName,NAME:.metadata.name --all-namespaces
孤立pod解决
找到所有运行中的pod id
1kubectl get pods --all-namespaces -o custom-columns=PodUID:.metadata.uid | tail -n +2 > pods.txt
1ls -d1 /var/lib/kubelet/pods/* | xargs -I % bash -c '[ ! -f %/etc-hosts ] && echo %'
1cat /var/log/messages|grep -i 'Orphaned pod'|awk -F '"' '{print $2}'|uniq
1kubectl get pods --all-namespaces -o custom-columns=PodName:.metadata.name,PodUID:.metadata.uid | egrep -f /tmp/pods.txt
节点
禁止节点调度
1kubectl cordon master # 禁止节点调度
1kubeclt uncordon master # 允许节点调度
Label添加删除和修改
-
查看
1kubectl get node --show-labels -
添加
1kubectl label nodes <node-name> <label-key>=<label-value> -
删除
1kubectl label nodes <node-name> <label-key>- -
修改
1kubectl label nodes <node-name> <label-key>=<label-value> --overwrite
知识共享署名-非商业性使用-相同方式共享4.0国际许可协议