Last active
August 5, 2021 00:46
-
-
Save Yapcheekian/a2149771afdf27573c75178896459691 to your computer and use it in GitHub Desktop.
capture pod packet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# https://mp.weixin.qq.com/s?__biz=MzA4MzIwNTc4NQ==&mid=2247484821&idx=1&sn=aaa173a8b913cc759c56efe05d2c15ad&chksm=9ffb4e63a88cc7755ca720b3886946245246d8e57687cf209ad47f61a186cc290c04ef57fc91&scene=21#wechat_redirect | |
function e_net() { | |
set -eu | |
pod=`kubectl get pod ${pod_name} -n ${namespace} -o template --template='{{range .status.containerStatuses}}{{.containerID}}{{end}}' | sed 's/docker:\/\/\(.*\)$/\1/'` | |
pid=`docker inspect -f {{.State.Pid}} $pod` | |
echo -e "\033[32m Entering pod netns for ${namespace}/${pod_name} \033[0m\n" | |
cmd="nsenter -n -t ${pid}" | |
echo -e "\033[32m Execute the command: ${cmd} \033[0m" | |
${cmd} | |
} | |
# 运行函数 | |
pod_name=$1 | |
namespace=${2-"default"} | |
e_net |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment