Repository navigation
Support for troubleshooting distroless containers #27140
Description
I favor running distroless container images in production, usually built from SCRATCH with the binary and bare minimum of libraries. This has a number of benefits and works well the vast majority of the time, but it's difficult on the occasion where I need to troubleshoot something in production.
It'd be nice if there was a way to enable some sort of debug mode for a running pod where a set of tools could be attached that I could then exec within the container.
I'm willing to do the work to develop this feature, if necessary, but I'm not exactly sure what the next steps should be. I'm opening this issue to find out if anyone is working on something similar and/or get early guidance on how this could fit into the Kubernetes road map.
If it's the case that no one else is working on something similar and such a feature would be welcomed, my expectation is the next step would be to write a design proposal.
Tracking issue: kubernetes/enhancements#277
KEP: https://git.k8s.io/enhancements/keps/sig-node/20190212-ephemeral-containers.md
PRs:
- Add helpers for iterating containers in a pod #79176: Helpers for iterating containers in a pod
- Add Ephemeral Containers to the Kubernetes core API #59416 Ephemeral containers API
- Add integration test for ephemeral containers #79216 Integration test for ephemeral containers API
- Improve API documentation for ephemeral containers #79614 Improve ephemeral containers API documentation
- Add support for Ephemeral Containers to the kubelet #59484 Basic kubelet support for ephemeral containers
- Print ephemeral containers in kubectl describe #80847 Allow kubectl to attach to ephemeral containers #80644 Update kubectl polymorphic logs helper for ephemeral containers #82010 kubectl updates for interacting with ephemeral containers
- Update admission plugins for ephemeral containers #81936 Update admission plugins for ephemeral containers
- Add ephemeral containers to streamLocation name suggestions #81678 Add ephemeral containers to stream locations container name suggestions
- WIP: Remove ephemeral container lists from API exceptions #84519: Annotate with listType and remove from
api/api-rules/violation_exceptions.list
Activity
therc commentedon Jun 13, 2016
Maybe just use shared PID namespaces in Docker 1.12 (and rkt's equivalent, if/when it's there): moby/moby#10163
You'd create a new container with a debug image (or one of many) and attach it to the existing pod.
verb commentedon Jun 13, 2016
Ah, that would be perfect! I see that #1615 exists for sharing a PID namespace in a pod, which also led me to discover this issue may very well be a dupe of #24957 (though @smarterclayton only mentions debugging as one of many possible uses).
Before I close this issue as a dupe, I just want to make sure I understand how it would work. I see two possibilities --
kubectl attach, but if I try to do this in 1.2 I get the errorspec.containers: Forbidden: pod updates may not add or remove containers. (am I doing this incorrectly?)Though not as useful as a debug container, something that could work in the interim would be to attach a volume to a running container, if that were possible. (In 1.2 it doesn't seem to be: spec: Forbidden: pod updates may not change fields other than
containers[*].imageorspec.activeDeadlineSeconds)smarterclayton commentedon Jun 13, 2016
Today, it's not possible to mutate a running pod. Attach connects to an existing container (if the Stdin and/or TTY flags were set).
Another option beyond those you mention above would be to allow adhoc container execution inside of a pod that mounts the majority of the namespaces of another container. I.e.:
/mnt/attach(or similar)Scheduling a new pod doesn't convey to the runtime that C should be cleaned up if 1/A is removed (which we want, probably). However, in the flow above C would have to share resources with A so there are various edge cases around guaranteed pods having no more CPU to spare for C.
Another option would be to implement container volumes #831 and mount your debug tools into your bare bones image. That's not adhoc though, so it doesn't quite fit your use case.
davidopp commentedon Jun 24, 2016
General observation: if we're going to make it possible to add containers to pods, we should do it in a general way, not just to cover this use case.
I can't imagine we're going to implement adding containers to pods soon though.
verb commentedon Jul 8, 2016
I've gotten a lot of great suggestions so far, so I thought I'd summarize them:
kubectl execinside of a running containerkubectl patchor equivalent) to add volumes. This would be especially useful in conjunction with Image volumes and container volumes #831 to support container images as volumes.kubectl execto allow executing commands from arbitrary container images which are then automatically fetched and run within the existing pod cgroup/pid/net/etc namespaces. (e.g.kubectl exec 123456-7890 -X gcr.io/debug-image -i -t -- bash)kubectl exec 123456-7890 -H /bin/busybox -i -t)I'm not yet familiar with the kubernetes implementation, but the volume solutions strike me as the easiest to implement and those requiring mutation of pods the most difficult.
The solutions that extend
kubectl exec"feel" the most natural to me as a user. The backend steps (read: docker commands to run) seem conceptually straightforward, but there may be some technical hurdles (e.g. I'm getting ptrace not permitted when attempting to strace across container images, but that's happening within the same image as well).I don't like coupling this functionality to the node, so I'll start down the road of writing a proposal to support
kubectl execof arbitrary container images (2i in the above list).thockin commentedon Jul 8, 2016
The idea of running a "toolbox" container that is not part of a pod, but has the same namespaces as the pod is cute, but a little scary and opaque.
If we allowed adding a container to a pod, it could just be a shiny form of that.
Another option might be to include a container in the pod that is "inactive" until later activated.
erictune commentedon Jul 8, 2016
How far do you get if you have your build system produce "debug" and "stripped" versions of your container image ("debug" has a base image with a debugger, and "stripped" does not)?
Normally, your service just has "stripped" containers, but if there is an active bug, you deploy one or more extra containers for that service which are "debug images", and wait for the problem to happen again.
Doesn't help if the problem only happens once, but who has time to debug that kind of problem anyhow?
erictune commentedon Jul 8, 2016
The key question I think is whether you do this by making a new pod, and pods stay immutable, or if we make pods mutable.
verb commentedon Jul 8, 2016
@thockin I'll grant you scary, but I'm not yet willing to concede that pulling in a different userland for a binary is any more opaque than your run-of-the-mill
kubectl exec. Both seem solvable.I'd be happy with an inactive container as long as it (optionally) automatically updates prior to activating so I'm not tied to an old debug image. The downside here is the extra boilerplate config in every pod I run.
smarterclayton commentedon Jul 8, 2016
I should note that we've had very good feedback from the "debug" command
(which spawns a copy of the pod with a shell, or other command, as the
target). It doesn't address the "I created a pod that has nothing useful
in it to debug", but it does address the bulk of the practical "w.t.h. is
this not starting up correctly" problems.
On Fri, Jul 8, 2016 at 7:16 PM, verb notifications@github.com wrote:
smarterclayton commentedon Jul 8, 2016
Debug also leads naturally to other hooks like
"--attach-and-mount=IMAGENAME" for getting access to debug tools.
On Fri, Jul 8, 2016 at 7:31 PM, Clayton Coleman ccoleman@redhat.com wrote:
verb commentedon Jul 8, 2016
@erictune Certainly workable, but I'm concerned about some downsides:
Even if I can't think of it right now, I'm confident there will eventually be a reason that I'll need to connect to a stripped container and it seems like a bit of a gap in the toolbox.
35 remaining items
verb commentedon Jan 28, 2020
/remove-lifecycle stale
fejta-bot commentedon Apr 27, 2020
Issues go stale after 90d of inactivity.
Mark the issue as fresh with
/remove-lifecycle stale.Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with
/close.Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
verb commentedon Apr 27, 2020
/remove-lifecycle stale
fejta-bot commentedon May 27, 2020
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with
/remove-lifecycle rotten.Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with
/close.Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
warmchang commentedon May 28, 2020
/remove-lifecycle rotten
fejta-bot commentedon Aug 26, 2020
Issues go stale after 90d of inactivity.
Mark the issue as fresh with
/remove-lifecycle stale.Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with
/close.Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale
verb commentedon Aug 27, 2020
This issue has become a sort of tracking issue for the overall problem of troubleshooting distroless containers, but tracking issues are a poor fit for k/k: the discussion dies down and it just into fighting lifecycle.
This issue motivated two enhancements: kubernetes/enhancements#277 (Ephemeral containers) and kubernetes/enhancements#1441 (kubectl debug). Let's track these efforts in their feature issues and consider this k/k issue closed.
Merge pull request kubernetes#45442 from verb/pod-tshoot-1