There is a container in my Kubernetes cluster which I want to debug.
But there is nonetstat
, no ip
and no apk
.
Is there a way to upgrade this image, so that the common tools are installed?
In this case it is the nginx container image in a K8s 1.23 cluster.
2
Answers
The whole point of using containers is to optimize the resource utilization in your cluster. The images used should only include the packages that are needed to run your app.
The unwanted packages should be removed from your images (especially in prod) to reduce the compute utilization and to reduce the attack vector.
This appears to be a stripped down image that has only the libraries needed to run that application.
In order to debug, you will have to create a new container in the same pid and network namespace as the container you are trying to debug
Build container first
Dockerfile
Build
Run
https://rothgar.medium.com/how-to-debug-a-running-docker-container-from-a-separate-container-983f11740dc6
Alpine is a stripped-down version of the image to reduce the footprint. So the absence of those tools is expected. Although since Kubernetes
1.23
, you can use thekubectl debug
command to attach a debug pod to the subject pod.Syntax:
Example:
In the below example, the
ubuntu
container is attached to the Nginx-alpine pod, requiring debugging. Also, note that theps -eaf
output shows nginx process running and thecat /etc/os-release
shows ubuntu running. The indicating process is shared/visible between the two containers.Debugging as ubuntu as seen here, this arm us with all sort of tools:
In case ephemeral containers need to be enabled in your cluster, then you can enable it via feature gates as described here.