GithubHelp home page GithubHelp logo

Comments (5)

aylei avatar aylei commented on August 10, 2024 1

It depends on the path of your tcp dump file, if you save the file under /proc/1/root/ then you can access the file directly in the root filesystem of your application container, otherwise you have to locate the file under the root filesystem of the debug container.

For example, if you save the tcpdump data to /proc/1/root/tmp/tcpdump in the debug container, then you can copy this file via:

kubectl cp -n <namespace> <application-pod-name>:/tmp/tcpdump -c <application-container-name> ./tcpdump 

However, if you save the file to /tmp/tcpdump in the debug container, you should run the following command:

kubectl cp -n <namespace> <application-pod-name>:/proc/{debug-container-pid}/root/tmp/tcpdump -c <application-container-name> ./tcpdump 

from kubectl-debug.

smallersoup avatar smallersoup commented on August 10, 2024

[root@master ~]# kubectl debug litemall-all-7f7b98487-kb27g --agentless --port-forward
Agent Pod info: [Name:debug-agent-pod-e1fbf12f-2d0b-11ea-8ded-5254003c4391, Namespace:default, Image:aylei/debug-agent:latest, HostPort:10027, ContainerPort:10027]
Waiting for pod debug-agent-pod-e1fbf12f-2d0b-11ea-8ded-5254003c4391 to run...
pod litemall-all-7f7b98487-kb27g PodIP 10.100.219.100, agentPodIP 172.21.0.15
wait for forward port to debug agent ready...
Forwarding from 127.0.0.1:10027 -> 10027
Forwarding from [::1]:10027 -> 10027
Handling connection for 10027
pulling image nicolaka/netshoot:latest...
latest: Pulling from nicolaka/netshoot
Digest: sha256:8b020dc72d8ef07663e44c449f1294fc47c81a10ef5303dc8c2d9635e8ca22b1
Status: Image is up to date for nicolaka/netshoot:latest
starting debug container...
container created, open tty...
bash-5.0#
bash-5.0# cd /proc/1/root
bash-5.0# cd tmp/
bash-5.0# echo 11 > tcpdump
bash-5.0# ls -l
total 20
-rw-r--r-- 1 root root 2 Jan 2 01:48 1.txt
drwxr-xr-x 2 root root 4096 Dec 31 09:49 hsperfdata_root
-rw-r--r-- 1 root root 3 Jan 2 03:03 tcpdump
drwxr-xr-x 2 root root 4096 Dec 31 09:49 tomcat-docbase.373760562388174187.8080
drwxr-xr-x 3 root root 4096 Dec 31 09:49 tomcat.1895695548235022299.8080
bash-5.0# pwd
/proc/1/root/tmp
bash-5.0

[root@master ~]# kubectl cp -n default debug-agent-pod-e1fbf12f-2d0b-11ea-8ded-5254003c4391:/tmp/tcpdump ./tcpdump

command terminated with exit code 126

from kubectl-debug.

smallersoup avatar smallersoup commented on August 10, 2024

@aylei Hello, following your instructions, I still get an error

from kubectl-debug.

smallersoup avatar smallersoup commented on August 10, 2024

[root@master ~]# kubectl cp default/debug-agent-pod-e1fbf12f-2d0b-11ea-8ded-5254003c4391:/tmp/tcpdump ./tcpdump --v=10

I0102 11:12:30.470357 22693 round_trippers.go:423] curl -k -v -XPOST -H "X-Stream-Protocol-Version: v4.channel.k8s.io" -H "X-Stream-Protocol-Version: v3.channel.k8s.io" -H "X-Stream-Protocol-Version: v2.channel.k8s.io" -H "X-Stream-Protocol-Version: channel.k8s.io" -H "User-Agent: kubectl/v1.16.3 (linux/amd64) kubernetes/b3cbbae" 'https://172.21.0.15:6443/api/v1/namespaces/default/pods/debug-agent-pod-e1fbf12f-2d0b-11ea-8ded-5254003c4391/exec?command=tar&command=cf&command=-&command=%2Ftmp%2Ftcpdump&container=debug-agent&stderr=true&stdout=true'
I0102 11:12:30.493746 22693 round_trippers.go:443] POST https://172.21.0.15:6443/api/v1/namespaces/default/pods/debug-agent-pod-e1fbf12f-2d0b-11ea-8ded-5254003c4391/exec?command=tar&command=cf&command=-&command=%2Ftmp%2Ftcpdump&container=debug-agent&stderr=true&stdout=true 101 Switching Protocols in 23 milliseconds
I0102 11:12:30.493760 22693 round_trippers.go:449] Response Headers:
I0102 11:12:30.493766 22693 round_trippers.go:452] Date: Thu, 02 Jan 2020 03:12:30 GMT
I0102 11:12:30.493770 22693 round_trippers.go:452] Connection: Upgrade
I0102 11:12:30.493774 22693 round_trippers.go:452] Upgrade: SPDY/3.1
I0102 11:12:30.493777 22693 round_trippers.go:452] X-Stream-Protocol-Version: v4.channel.k8s.io
F0102 11:12:30.587480 22693 helpers.go:114] command terminated with exit code 126
[root@master ~]#

from kubectl-debug.

aylei avatar aylei commented on August 10, 2024

@liabio The file is stored in the target Pod, not the debug agent, try kubectl cp litemall-all-7f7b98487-kb27g😁

from kubectl-debug.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.