Send a Signal to a Kubernetes App: a Slim Container Case

Rajesh
2 min readApr 22, 2024

From Iximiuz Labs

Try this challenge using below link

Scenario:

There’s a Pod called lonely running in the default namespace, acting as a simple HTTP server. Oddly enough, it chooses a random port to listen on each time it starts. Your job is to figure out which port this server is using and then send an HTTP request to it. To add to the challenge, there's no shell available in the container, and your access to the cluster is quite limited.

My Attempt:

  • There is pod called slim and the container(app) in the pod have no shell. To debug such container in pod , kubernetes have a special type of container called ephemeral container. We will attach an ephemeral container alongside the main application container(app) in the pod.
  • Please refer iximiuz blog on ephemeral container to understand it better.
  • We can use kubectl debug command to launch a ephemeral container (we have to pick the ephemeral container image contains tools to debug). You can also launch it by editing the pod manifest file. I have chosen busybox image for ephemeral container.
  • To effectively tweak signals to the HTTP server, both containers must utilize a shared PID namespace; otherwise, it will not serve its intended purpose. The kubectl debug command includes a flag called target, which is used to specify a shared PID namespace for the container you are targeting within a pod.
#kubectl debug -it <podName> --image=<ephemeralImage> --target=<container which you want to share pid namespace>>
kubectl debug -it slim --image=busybox --target=app
  • Now using Linux utility ps to list all the process. we find out the HTTP server process id as 1.
ps -ef
  • Now we need to send Custom user signal such as SIGUSR1 to pid 1 to finish the task.
  • We can use kill command with flag -SIGUSR1 along with pid to send the signal.
kill -SIGUSR1 1
  • I can verify that I have successfully completed the challenge by checking the status on the website (as shown in the image above).

For DevOps related blogs and challenges, pleased visit iximiuz.com . It provides In-depth articles of docker and kubernetes which is a gold mine for those who want to understand internals of containers and orchestration.

Thanks for reading this short article/write-up. Have a nice day

--

--