# kubectl debug
```
kubectl debug -it ephemeral-demo --image=busybox:1.28 --target=ephemeral-demo
kubect debug -it <pod_name> --image=<image_as_debug_tool> --target=<target_container_name>
```
```
## 原本Pod無 top / ps指令
❯ oc exec -it caturday-6c5f74f5d6-72zs4 top
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
Defaulted container "caturday" out of: caturday, debugger-lnwnh (ephem)
ERRO[0000] exec failed: unable to start container process: exec: "top": executable file not found in $PATH
command terminated with exit code 255
❯ oc exec -it caturday-6c5f74f5d6-72zs4 ps
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
Defaulted container "caturday" out of: caturday, debugger-lnwnh (ephem)
ERRO[0000] exec failed: unable to start container process: exec: "ps": executable file not found in $PATH
command terminated with exit code 255
## 利用kubectl debug attach一個具備指令的container
❯ kubectl debug -n jace -it caturday-6c5f74f5d6-72zs4 --image=quay.io/bedrock/ubuntu:xenial-20210804 --target=caturday
Targeting container "caturday". If you don't see processes from this container it may be because the container runtime doesn't support this feature.
Defaulting debug container name to debugger-lnwnh.
If you don't see a command prompt, try pressing enter.
1000700000@caturday-6c5f74f5d6-72zs4:/$
1000700000@caturday-6c5f74f5d6-72zs4:/$
1000700000@caturday-6c5f74f5d6-72zs4:/$ ps
PID TTY TIME CMD
36 pts/0 00:00:00 bash
44 pts/0 00:00:00 ps
1000700000@caturday-6c5f74f5d6-72zs4:/$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
1000700+ 1 0.0 0.0 109992 1928 ? Ssl 01:46 0:00 /caturday
1000700+ 36 0.2 0.0 18236 3268 pts/0 Ss 02:44 0:00 /bin/bash
1000700+ 45 0.0 0.0 34428 2848 pts/0 R+ 02:45 0:00 ps aux
1000700000@caturday-6c5f74f5d6-72zs4:/$ top
top - 02:45:18 up 1:00, 0 users, load average: 4.18, 3.42, 4.23
Tasks: 3 total, 1 running, 2 sleeping, 0 stopped, 0 zombie
%Cpu(s): 14.7 us, 7.6 sy, 0.0 ni, 75.0 id, 0.2 wa, 1.6 hi, 1.0 si, 0.0 st
KiB Mem : 16352232 total, 295352 free, 11517608 used, 4539272 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 3786044 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 1000700+ 20 0 109992 1928 0 S 0.0 0.0 0:00.10 caturday
```