|
| 1 | +# Debug arbitrary container PIDs with Squash |
| 2 | + |
| 3 | +At one point, Squash assumed that a user's debug target was completely described by the selection of: namespace, pod name, container. Squash assumed that the user wanted to debug the first process in the container. This is a reasonable assumption, since a popular container usage pattern is to specify one process per container. However it may be useful to run multiple processes in a single container. In order for squash to debug an arbitrary process, it needs to be told how to choose among the available processes. |
| 4 | + |
| 5 | +# Demonstration of the properties of multi-process containers |
| 6 | + |
| 7 | +This directory includes files needed to build and deploy a sample app as the first process in one container and the second process in a separate container. |
| 8 | + |
| 9 | +## Build and push the containers |
| 10 | + |
| 11 | +*This step is not needed, as the container images are already available with the values shown below. If you change these values you will need to update the manifests similarly.* |
| 12 | + |
| 13 | +```bash |
| 14 | +export CONTAINER_REPO_ORG = docker.io/soloio |
| 15 | +IMAGE_TAG=v0.0.2 make all |
| 16 | +``` |
| 17 | + |
| 18 | +## Deploy the containers |
| 19 | + |
| 20 | +We will deploy our sample containers in their own pods: |
| 21 | + |
| 22 | +```bash |
| 23 | +kubectl apply -f single.yaml |
| 24 | +kubectl apply -f multi.yaml |
| 25 | +``` |
| 26 | + |
| 27 | +## Inspect the images |
| 28 | + |
| 29 | +Note that the container with a single process features our app in PID 1 |
| 30 | + |
| 31 | +```bash |
| 32 | +k exec -it squash-demo-multiprocess-base-6c746c8595-kpsvt -- /bin/s |
| 33 | +h |
| 34 | +/app # ls |
| 35 | +sample_app |
| 36 | +/app # ps |
| 37 | +PID USER TIME COMMAND |
| 38 | + 1 root 0:00 ./sample_app |
| 39 | + 19 root 0:00 /bin/sh |
| 40 | + 26 root 0:00 ps |
| 41 | +``` |
| 42 | + |
| 43 | +However, for our multi-process container, our app is not PID 1 |
| 44 | + |
| 45 | +```bash |
| 46 | +k exec -it squash-demo-multiprocess-5fbdcd96cf-k9bzw -- /bin/sh |
| 47 | +/app # ls |
| 48 | +call_app.sh sample_app |
| 49 | +/app # ps |
| 50 | +PID USER TIME COMMAND |
| 51 | + 1 root 0:00 {call_app.sh} /bin/sh ./call_app.sh |
| 52 | + 7 root 0:00 ./sample_app |
| 53 | + 20 root 0:00 /bin/sh |
| 54 | + 27 root 0:00 ps |
| 55 | +``` |
| 56 | + |
| 57 | +## Debug the processes with squash |
| 58 | + |
| 59 | +You can debug the single process container without passing any flags. Squash will use the first PID by default. This works fine with our single process example. |
| 60 | + |
| 61 | +```bash |
| 62 | +squashctl # follow interactive prompt to choose target debug container |
| 63 | +``` |
| 64 | + |
| 65 | +To debug a multi-process container, you need to specify a process-identifier string. Squash will look for processes whos invocation comand matches the string provided. |
| 66 | + |
| 67 | +```bash |
| 68 | +squashctl --process sample_app # matches with case-insensitive regex |
| 69 | +``` |
0 commit comments