I want to run a multi-container pod, and interactuate with it via a terminal.
With kubectl run -ti
I can run a monocontainer pod and attach easily to it.
I think I have to kubectl apply
to create a complex pod, and later attach to it.
I’ve tried this and it doesn’t work:
kubectl run alpine --image alpine pod/alpine created
kubectl attach -i alpine If you don't see a command prompt, try pressing enter.
error: unable to upgrade connection: container alpine not found in pod alpine
I’m using latest k3s v1.25.4+k3s1
under a Linux host (Ubuntu 22.04).
2
Answers
This does work:
I need an auxiliary
sleep
.You need attach interactively first:
kubectl run -it alpine --image alpine
Then detach by using CTRL-P, then CTRL-Q
To reattach, you then use:
kubectl attach alpine -c alpine -i -t
Note that if you close the shell at any point, you terminate the pod, and it will restart