Skip to content

Commit

Permalink
support kube-tools get-pod-by-node.
Browse files Browse the repository at this point in the history
  • Loading branch information
xuxinkun committed Nov 8, 2019
1 parent a5224a7 commit 07e122f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ git clone https://github.com/xuxinkun/littleTools
cd littleTools
chmod +x install.sh
./install.sh
source /etc/profile
```

## docker tools(docker-tools)
Expand Down Expand Up @@ -44,13 +45,14 @@ chmod +x install.sh
| kt-get-node-notready | None | List all the not ready nodes. |
| kt-get-node-all | None | List all the nodes |
| kt-get-pod | {pod name} or {namespace} {pod name} | Describe pod. |
| kt-get-pod-node | {pod name} or {namespace} {pod name} | Get the pod and the node with pod. |
| kt-get-node-by-pod | {pod name} or {namespace} {pod name} | Get the pod and the node with pod. |
| kt-get-pod-all | None | Get all the pods of all namespaces. |
| kt-get-pod-by-ns | {namespace} | Get all the pods in the namespace. |
| kt-get-pod-by-rs | {rs name} or {namespace} {rs name} | Get all the pods of the rs. |
| kt-get-pod-by-deploy | {deploy name} or {namespace} {deploy name} | Get all the pods of the deploy. |
| kt-get-pod-by-svc | {svc name} or {namespace} {svc name} | Get all the pods of the svc. |
| kt-get-pod-by-ip | {ip} | Get pod with the ip. |
| kt-get-pod-by-node | {nodeName} | get pods on the node. |

## azk8spull

Expand Down
10 changes: 7 additions & 3 deletions examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Node: 111.22.201.39/111.22.201.39
Start Time: Mon, 12 Nov 2018 21:49:16 +0800
Labels: app=nevermore
[root@localhost ~]# kt-get-pod-node nevermore nevermore-a76210c9
[root@localhost ~]# kt-get-node-by-pod nevermore nevermore-a76210c9
NAME READY STATUS RESTARTS AGE IP NODE
nevermore-a76210c9 1/1 Running 2 128d 10.182.39.226 111.22.201.39
NAME STATUS ROLES AGE VERSION EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
Expand All @@ -98,6 +98,10 @@ NAME READY STATUS RESTARTS AGE IP NO
nevermore-a76210c9 1/1 Running 2 128d 10.182.39.226 111.22.201.39
[root@localhost ~]# kt-get-pod-by-ip 10.182.39.226
NAME READY STATUS RESTARTS AGE IP NODE
nevermore-a76210c9 1/1 Running 2 128d 10.182.39.226 111.22.201.39
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE
nevermore nevermore-a76210c9 1/1 Running 2 128d 10.182.39.226 111.22.201.39
[root@localhost ~]# kt-get-pod-by-node 111.22.201.39
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE
nevermore nevermore-a76210c9 1/1 Running 2 128d 10.182.39.226 111.22.201.39
```
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

mkdir -p /etc/littletools
cp -r * /etc/littletools/
sed -i '/source \/etc\/littletools\/littletools.sh/d' /etc/profile
sed -i '$a source /etc/littletools/littletools.sh' /etc/profile
source /etc/profile
32 changes: 20 additions & 12 deletions kube-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ function kt-get-node-notready()
{
kubectl get node -o wide|grep NotReady
}
function kt-get-node-by-pod()
{
if [[ $# == 2 ]]
then
kubectl get pod -n $1 $2 -o wide
node_name=`kubectl get pod -n $1 $2 -o go-template --template="{{.spec.nodeName}}"`
else
kubectl get pod $1
node_name=`kubectl get pod $1 -o go-template --template="{{.spec.nodeName}}"`
fi
kubectl describe node $node_name
}
function kt-get-node-all()
{
kubectl get node -o wide
Expand All @@ -42,18 +54,7 @@ function kt-get-pod()
kubectl describe pod $1
fi
}
function kt-get-pod-node()
{
if [[ $# == 2 ]]
then
kubectl get pod -n $1 $2 -o wide
node_name=`kubectl get pod -n $1 $2 -o go-template --template="{{.spec.nodeName}}"`
else
kubectl get pod $1
node_name=`kubectl get pod $1 -o go-template --template="{{.spec.nodeName}}"`
fi
kubectl get node $node_name -o wide
}

function kt-get-pod-all()
{
kubectl get pod --all-namespaces -o wide
Expand Down Expand Up @@ -108,4 +109,11 @@ function kt-get-pod-by-ip()
then
kubectl get pod --all-namespaces --field-selector="status.podIP=$1" -o wide
fi
}
function kt-get-pod-by-node()
{
if [[ $# == 1 ]]
then
kubectl get pod --all-namespaces --field-selector="spec.nodeName=$1" -o wide
fi
}

0 comments on commit 07e122f

Please sign in to comment.