-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin/trace-dns: Trace DNS requests using Inspektor Gadget (#2986)
Signed-off-by: Qasim Sarfraz <qasimsarfraz@microsoft.com>
- Loading branch information
1 parent
f716bf4
commit 1c38806
Showing
2 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Author: Qasim Sarfraz | ||
# Trace DNS requests for containers, pods, and nodes | ||
# Requires kubectl version 1.30 or later | ||
# https://github.com/inspektor-gadget/inspektor-gadget | ||
# https://www.inspektor-gadget.io/docs/latest/gadgets/trace_dns | ||
plugins: | ||
trace-dns: | ||
shortCut: Shift-D | ||
description: Trace DNS requests | ||
scopes: | ||
- containers | ||
- pods | ||
- nodes | ||
command: bash | ||
confirm: false | ||
background: false | ||
args: | ||
- -c | ||
- | | ||
IG_VERSION=v0.34.0 | ||
IG_IMAGE=ghcr.io/inspektor-gadget/ig:$IG_VERSION | ||
IG_FIELD=k8s.podName,src,dst,qr,qtype,name,rcode,latency_ns | ||
GREEN='\033[0;32m' | ||
RED='\033[0;31m' | ||
BLUE='\033[0;34m' | ||
NC='\033[0m' # No Color | ||
# Ensure kubectl version is 1.30 or later | ||
KUBECTL_VERSION=$(kubectl version --client | awk '/Client Version:/{print $3}') | ||
if [[ "$(echo "$KUBECTL_VERSION" | cut -d. -f2)" -lt 30 ]]; then | ||
echo -e "${RED}kubectl version 1.30 or later is required${NC}" | ||
sleep 3 | ||
exit | ||
fi | ||
clear | ||
# Handle containers | ||
if [[ -n "$POD" ]]; then | ||
echo -e "${GREEN}Tracing DNS requests for container ${BLUE}${NAME}${GREEN} in pod ${BLUE}${POD}${GREEN} in namespace ${BLUE}${NAMESPACE}${NC}" | ||
IG_NODE=$(kubectl get pod "$POD" -n "$NAMESPACE" -o jsonpath='{.spec.nodeName}') | ||
kubectl debug --kubeconfig=$KUBECONFIG --context=$CONTEXT -q \ | ||
--profile=sysadmin "node/$IG_NODE" -it --image="$IG_IMAGE" -- \ | ||
ig run trace_dns:$IG_VERSION -F "k8s.podName==$POD" -F "k8s.containerName=$NAME" \ | ||
--fields "$IG_FIELD" | ||
exit | ||
fi | ||
# Handle pods | ||
if [[ -n "$NAMESPACE" ]]; then | ||
echo -e "${GREEN}Tracing DNS requests for pod ${BLUE}${NAME}${GREEN} in namespace ${BLUE}${NAMESPACE}${NC}" | ||
IG_NODE=$(kubectl get pod "$NAME" -n "$NAMESPACE" -o jsonpath='{.spec.nodeName}') | ||
kubectl debug --kubeconfig=$KUBECONFIG --context=$CONTEXT -q \ | ||
--profile=sysadmin -it --image="$IG_IMAGE" "node/$IG_NODE" -- \ | ||
ig run trace_dns:$IG_VERSION -F "k8s.podName==$NAME" \ | ||
--fields "$IG_FIELD" | ||
exit | ||
fi | ||
# Handle nodes | ||
echo -e "${GREEN}Tracing DNS requests for node ${BLUE}${NAME}${NC}" | ||
kubectl debug --kubeconfig=$KUBECONFIG --context=$CONTEXT -q \ | ||
--profile=sysadmin -it --image="$IG_IMAGE" "node/$NAME" -- \ | ||
ig run trace_dns:$IG_VERSION --fields "$IG_FIELD" |