如何使用 kubectl 运行 具有多个命令的 pod 并在之后保持交互 shell?

How to run a pod with multiple commands and keeping an interactive shell after that with kubectl?

我运行这个命令去获取一个交互式的shell inside a pod in kubernetes:

kubectl run my-shell --generator=run-pod/v1 --rm -it --image alpine -- sh

效果很好,但我经常在交互式 shell 启动后再执行 运行 一个命令:

apk add curl

我不知道如何组合这些命令,以便在安装 curl 后获得交互式 shell。有可能吗?我尝试了一些其他方法,例如 shell 的 -c 参数,但它在安装 curl 后完成执行。

使用 sh -c "apk add curl && sh" 适合我:

$ kubectl run my-shell --generator=run-pod/v1 --rm -it --image alpine -- sh -c "apk add curl && sh"
If you don't see a command prompt, try pressing enter.

/ # curl --version
curl 7.65.1 (x86_64-alpine-linux-musl) libcurl/7.65.1 OpenSSL/1.1.1c zlib/1.2.11 nghttp2/1.38.0
Release-Date: 2019-06-05
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL TLS-SRP UnixSockets

/ # exit
Session ended, resume using 'kubectl attach my-shell -c my-shell -i -t' command when the pod is running
pod "my-shell" deleted

我的kubectl version:

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:11:31Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:02:58Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}