How to use ephemeral container for debug pod in k8s 1.18

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information:

Kubernetes version: 1.18
Cloud being used: Self-built cluster
Installation method:
Host OS: Centos
CNI and version:
CRI and version: Docker

You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.

I learned from the information that k8s1.18 can also support ephemeral containers.

I enabled this feature by modifying the api-server

- --feature-gates=EphemeralContainers=true

However, when I executed the debug command, I did not achieve the expected interactive debugging of the business pod effect. The terminal seemed to be stuck.

$ kubectl alpha debug <biz_pod> -i -t --image=busybox -- /bin/sh
Defaulting debug container name to debugger-ttxgk.
<stuck forever>

I checked the business pod and found that the container had been injected.

$ kubectl get pod <biz_pod> -o yaml
...
- image: busybox
    imagePullPolicy: IfNotPresent
    name: debugger-pg4vf
    resources: {}
    stdin: true
    terminationMessagePolicy: File
    tty: true
  - command:
    - /bin/sh
    image: busybox
    imagePullPolicy: IfNotPresent
    name: debugger-45fzq
    resources: {}
    stdin: true
    terminationMessagePolicy: File
  - command:
    - /bin/sh
    image: busybox
    imagePullPolicy: IfNotPresent
    name: debugger-sjgh7
    resources: {}
    stdin: true
    terminationMessagePolicy: File
    tty: true
...

When I log the ephemeral container, the error is as follows

kubectl logs <biz_pod> -c debugger-ttxgk
Error from server (NotFound): the server could not find the requested resource ( pods/log <biz_pod>)

Is it because I am missing some configuration or the command is wrong? Is there a way to delete the ephemeral container without affecting the pod? Looking forward to your reply.

PS: due to business reasons, it is impossible to upgrade the k8s cluster to 1.25 of the ephemeral container feature stable