kubectl icon indicating copy to clipboard operation
kubectl copied to clipboard

Allow removing fields from kubectl debug copied pods or containers

Open Sayrus opened this issue 1 year ago • 1 comments

What would you like to be added: A way to remove fields from containers when using kubectl debug --copy-to using --custom patches.

Why is this needed: When using kubectl debug with the --copy-to option, everything from the original pod is copied. In my case, this includes livenessProbe and readinessProbe. In many cases, these probes fail. For instance:

  • When profiling, livenessProbe or readinessProbe may timeout (Related but for ephemeral containers: https://github.com/kubernetes/kubernetes/issues/57187)
  • The same happens when debugging with blocking breakpoints
  • When the image or entrypoint has been modified or if the app is not started with the same options as the original (using --image or simply COMMAND [args...])

Thanks to KEP-4292 implemented behind a flag here, it is now possible to rewrite fields so we can "disable" probes by setting a very high initial delay instead. It also allows overwriting environment variable and other stuffs. Unfortunately, since we can't unset fields, we can't do things such as adding an exec probe to a pod with httpGet probe (as it results in a spec with both httpGet and exec which is invalid)

The specific case of probes can be mitigated by using a profile that automatically removes probes (such as general) but this introduces some other limitations if your debugging job requires other capabilities.

I saw https://github.com/kubernetes/kubernetes/pull/123149 which implements this using --keep-* parameters. For my use-case and I would prefer being able to distribute custom profiles as YAML or JSON as it allows non power-user to use different debugging profiles without changing several kubectl arguments.

For client-side patching, Strategic Merge Patch directives are used (or used to? I know it exists as well in Kustomize.). Following this document, a patch to remove probes and a specific env variable could look like:

{
  "env": [
    {
      "name": "DELETE_ME",
      "$patch": "delete"
    }
  ],
  "livenessProbe": null,
  "readinessProbe": null
}

Sayrus avatar Mar 06 '24 16:03 Sayrus

Thanks for opening this issue. As we discussed async on ~Slack~ Email, I agree with that probes should be manageable via flag because I don't think --custom flag will ever be able to support removal of fields; /triage accepted /priority backlog

ardaguclu avatar Mar 07 '24 10:03 ardaguclu

This is fixed by https://github.com/kubernetes/kubernetes/pull/123149

ardaguclu avatar May 07 '24 11:05 ardaguclu