Skip to content

Instantly share code, notes, and snippets.

@Yapcheekian
Last active August 5, 2021 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yapcheekian/a2149771afdf27573c75178896459691 to your computer and use it in GitHub Desktop.
Save Yapcheekian/a2149771afdf27573c75178896459691 to your computer and use it in GitHub Desktop.
capture pod packet
#!/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