kubectl-debug icon indicating copy to clipboard operation
kubectl-debug copied to clipboard

如何将debug-agent中的文件复制出来

Open woniuzhang opened this issue 4 years ago • 3 comments

kubectl cp 报错 error: unexpected EOF

woniuzhang avatar Apr 10 '20 01:04 woniuzhang

could you please give us more details for this error? or you can diagnose by using kubectl --v=8 cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar.

markzhang0928 avatar Apr 10 '20 07:04 markzhang0928

我也遇到 cp 不出来的问题,cp 报如下错误:

$ kubectl --v=8 cp debug-agent-pod-c591f1e0-8f64-11ea-90cc-82962ec51401:/tmp/auth.pcap auth.pcap command terminated with exit code 126

$ kubectl --v=8 cp debug-agent-pod-c591f1e0-8f64-11ea-90cc-82962ec51401:/tmp/auth.pcap auth.pcap I0506 14:57:56.469437 37254 loader.go:359] Config loaded from file: /Users/chengyt/.kube/config I0506 14:57:56.476622 37254 round_trippers.go:416] GET https://127.0.0.1:8443/api/v1/namespaces/default/pods/debug-agent-pod-c591f1e0-8f64-11ea-90cc-82962ec51401 I0506 14:57:56.476642 37254 round_trippers.go:423] Request Headers: I0506 14:57:56.476647 37254 round_trippers.go:426] Accept: application/json, / I0506 14:57:56.476650 37254 round_trippers.go:426] User-Agent: kubectl/v1.15.5 (darwin/amd64) kubernetes/20c265f I0506 14:57:56.506425 37254 round_trippers.go:441] Response Status: 200 OK in 29 milliseconds I0506 14:57:56.506450 37254 round_trippers.go:444] Response Headers: I0506 14:57:56.506456 37254 round_trippers.go:447] Content-Type: application/json I0506 14:57:56.506460 37254 round_trippers.go:447] Content-Length: 3273 I0506 14:57:56.506463 37254 round_trippers.go:447] Date: Wed, 06 May 2020 06:59:04 GMT I0506 14:57:56.506520 37254 request.go:947] Response Body: {"kind":"Pod","apiVersion":"v1","metadata":{"name":"debug-agent-pod-c591f1e0-8f64-11ea-90cc-82962ec51401","namespace":"default","selfLink":"/api/v1/namespaces/default/pods/debug-agent-pod-c591f1e0-8f64-11ea-90cc-82962ec51401","uid":"3b7437b0-1cb3-4598-a604-51af12ae2a49","resourceVersion":"3726256","creationTimestamp":"2020-05-06T06:43:44Z"},"spec":{"volumes":[{"name":"docker","hostPath":{"path":"/var/run/docker.sock","type":""}},{"name":"cgroup","hostPath":{"path":"/sys/fs/cgroup","type":""}},{"name":"lxcfs","hostPath":{"path":"/var/lib/lxc","type":"DirectoryOrCreate"}},{"name":"vardata","hostPath":{"path":"/var/data","type":""}},{"name":"runcontainerd","hostPath":{"path":"/run/containerd","type":""}},{"name":"runrunc","hostPath":{"path":"/run/runc","type":""}},{"name":"default-token-tz25v","secret":{"secretName":"default-token-tz25v","defaultMode":420}}],"containers":[{"name":"debug-agent","image":"aylei/debug-agent:latest","ports":[{"name":"http","hostPort":10027,"containerPort":10027,"protocol":"TCP"}],"re [truncated 2249 chars] I0506 14:57:56.511324 37254 round_trippers.go:416] POST https://127.0.0.1:8443/api/v1/namespaces/default/pods/debug-agent-pod-c591f1e0-8f64-11ea-90cc-82962ec51401/exec?command=tar&command=cf&command=-&command=%2Ftmp%2Fauth.pcap&container=debug-agent&stderr=true&stdout=true I0506 14:57:56.511391 37254 round_trippers.go:423] Request Headers: I0506 14:57:56.511408 37254 round_trippers.go:426] X-Stream-Protocol-Version: v4.channel.k8s.io I0506 14:57:56.511419 37254 round_trippers.go:426] X-Stream-Protocol-Version: v3.channel.k8s.io I0506 14:57:56.511424 37254 round_trippers.go:426] X-Stream-Protocol-Version: v2.channel.k8s.io I0506 14:57:56.511430 37254 round_trippers.go:426] X-Stream-Protocol-Version: channel.k8s.io I0506 14:57:56.511437 37254 round_trippers.go:426] User-Agent: kubectl/v1.15.5 (darwin/amd64) kubernetes/20c265f I0506 14:57:56.608557 37254 round_trippers.go:441] Response Status: 101 Switching Protocols in 97 milliseconds I0506 14:57:56.608606 37254 round_trippers.go:444] Response Headers: I0506 14:57:56.608619 37254 round_trippers.go:447] Date: Wed, 06 May 2020 06:59:04 GMT I0506 14:57:56.608626 37254 round_trippers.go:447] Connection: Upgrade I0506 14:57:56.608631 37254 round_trippers.go:447] Upgrade: SPDY/3.1 I0506 14:57:56.608638 37254 round_trippers.go:447] X-Stream-Protocol-Version: v4.channel.k8s.io F0506 14:57:56.728209 37254 helpers.go:114] command terminated with exit code 126

另外,此文件在 debug-agent-pod 中是存在的 bash-5.0# ls -l /tmp/auth.pcap -rw-r--r-- 1 root root 22092 May 6 06:49 /tmp/auth.pcap

还有直接执行 exec 会有各种出错,如何才能 exec -it ... sh 进去?

$ kubectl exec debug-agent-pod-c591f1e0-8f64-11ea-90cc-82962ec51401 -- ls -l /tmp/auth.pcap OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: "ls": executable file not found in $PATH": unknown command terminated with exit code 126

gnatecheng avatar May 06 '20 07:05 gnatecheng

复制的对象(target pod) 是目标业务容器,而不是debug-agent容器。

et.c [email protected] 于2020年5月6日周三 下午3:01写道:

我也遇到 cp 不出来的问题,cp 报如下错误:

$ kubectl --v=8 cp debug-agent-pod-c591f1e0-8f64-11ea-90cc-82962ec51401:/tmp/auth.pcap auth.pcap command terminated with exit code 126

$ kubectl --v=8 cp debug-agent-pod-c591f1e0-8f64-11ea-90cc-82962ec51401:/tmp/auth.pcap auth.pcap I0506 14:57:56.469437 37254 loader.go:359] Config loaded from file: /Users/chengyt/.kube/config I0506 14:57:56.476622 37254 round_trippers.go:416] GET https://127.0.0.1:8443/api/v1/namespaces/default/pods/debug-agent-pod-c591f1e0-8f64-11ea-90cc-82962ec51401 I0506 14:57:56.476642 37254 round_trippers.go:423] Request Headers: I0506 14:57:56.476647 37254 round_trippers.go:426] Accept: application/json, / I0506 14:57:56.476650 37254 round_trippers.go:426] User-Agent: kubectl/v1.15.5 (darwin/amd64) kubernetes/20c265f I0506 14:57:56.506425 37254 round_trippers.go:441] Response Status: 200 OK in 29 milliseconds I0506 14:57:56.506450 37254 round_trippers.go:444] Response Headers: I0506 14:57:56.506456 37254 round_trippers.go:447] Content-Type: application/json I0506 14:57:56.506460 37254 round_trippers.go:447] Content-Length: 3273 I0506 14:57:56.506463 37254 round_trippers.go:447] Date: Wed, 06 May 2020 06:59:04 GMT I0506 14:57:56.506520 37254 request.go:947] Response Body: {"kind":"Pod","apiVersion":"v1","metadata":{"name":"debug-agent-pod-c591f1e0-8f64-11ea-90cc-82962ec51401","namespace":"default","selfLink":"/api/v1/namespaces/default/pods/debug-agent-pod-c591f1e0-8f64-11ea-90cc-82962ec51401","uid":"3b7437b0-1cb3-4598-a604-51af12ae2a49","resourceVersion":"3726256","creationTimestamp":"2020-05-06T06:43:44Z"},"spec":{"volumes":[{"name":"docker","hostPath":{"path":"/var/run/docker.sock","type":""}},{"name":"cgroup","hostPath":{"path":"/sys/fs/cgroup","type":""}},{"name":"lxcfs","hostPath":{"path":"/var/lib/lxc","type":"DirectoryOrCreate"}},{"name":"vardata","hostPath":{"path":"/var/data","type":""}},{"name":"runcontainerd","hostPath":{"path":"/run/containerd","type":""}},{"name":"runrunc","hostPath":{"path":"/run/runc","type":""}},{"name":"default-token-tz25v","secret":{"secretName":"default-token-tz25v","defaultMode":420}}],"containers":[{"name":"debug-agent","image":"aylei/debug-agent:latest","ports":[{"name":"http","hostPort":10027,"containerPort":10027,"protocol":"TCP"}],"re [truncated 2249 chars] I0506 14:57:56.511324 37254 round_trippers.go:416] POST https://127.0.0.1:8443/api/v1/namespaces/default/pods/debug-agent-pod-c591f1e0-8f64-11ea-90cc-82962ec51401/exec?command=tar&command=cf&command=-&command=%2Ftmp%2Fauth.pcap&container=debug-agent&stderr=true&stdout=true I0506 14:57:56.511391 37254 round_trippers.go:423] Request Headers: I0506 14:57:56.511408 37254 round_trippers.go:426] X-Stream-Protocol-Version: v4.channel.k8s.io I0506 14:57:56.511419 37254 round_trippers.go:426] X-Stream-Protocol-Version: v3.channel.k8s.io I0506 14:57:56.511424 37254 round_trippers.go:426] X-Stream-Protocol-Version: v2.channel.k8s.io I0506 14:57:56.511430 37254 round_trippers.go:426] X-Stream-Protocol-Version: channel.k8s.io I0506 14:57:56.511437 37254 round_trippers.go:426] User-Agent: kubectl/v1.15.5 (darwin/amd64) kubernetes/20c265f I0506 14:57:56.608557 37254 round_trippers.go:441] Response Status: 101 Switching Protocols in 97 milliseconds I0506 14:57:56.608606 37254 round_trippers.go:444] Response Headers: I0506 14:57:56.608619 37254 round_trippers.go:447] Date: Wed, 06 May 2020 06:59:04 GMT I0506 14:57:56.608626 37254 round_trippers.go:447] Connection: Upgrade I0506 14:57:56.608631 37254 round_trippers.go:447] Upgrade: SPDY/3.1 I0506 14:57:56.608638 37254 round_trippers.go:447] X-Stream-Protocol-Version: v4.channel.k8s.io F0506 14:57:56.728209 37254 helpers.go:114] command terminated with exit code 126

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aylei/kubectl-debug/issues/97#issuecomment-624477279, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGITFQIO2PWL26U2DRKIHPDRQEDLLANCNFSM4MFEXJ5A .

markzhang0928 avatar May 07 '20 03:05 markzhang0928