[英]Kubernetes bash to POD after creation
I tried to create the POD using command kubectl run --generator=run-pod/v1 mypod--image=myimage:1 -it bash
and after successful pod creation it prompts for bash command in side container.我尝试使用命令
kubectl run --generator=run-pod/v1 mypod--image=myimage:1 -it bash
创建 POD,在成功创建 pod 后,它会提示在侧容器中输入 bash 命令。
Is there anyway to achieve above command using YML file?无论如何使用YML文件来实现上述命令? I tried below YML but it does not go to bash directly after successful creation of POD.
我在 YML 下尝试过,但在成功创建 POD 后,它不会直接从 go 到 bash。 I had to manually write command
kubectl exec -it POD_NAME bash
.我不得不手动编写命令
kubectl exec -it POD_NAME bash
。 But want to avoid using exec command to bash my container.但要避免对我的容器使用 exec 命令 bash。 I want my YML to take me to my container after creation of POD.
我希望我的 YML 在创建 POD 后将我带到我的容器。 is there anyway to achieve this?
有没有办法做到这一点?
apiVersion: v1
kind: Pod
metadata:
name: mypod
namespace: mynamespcae
labels:
app: mypod
spec:
containers:
- args:
- bash
name: mypod
image: myimage:1
stdin: true
stdinOnce: true
tty: true
This is a community wiki answer.这是一个社区维基答案。 Feel free to expand it.
随意扩展它。
As already mentioned by David, it is not possible to go to bash directly after a Pod is created by only using the YAML syntax.正如 David 已经提到的,在仅使用 YAML 语法创建 Pod 之后,不可能直接将 go 到 bash。 You have to use a proper
kubectl
command like kubectl exec
in order to Get a Shell to a Running Container .您必须使用正确的
kubectl
命令,例如kubectl exec
才能将Shell 获取到 Running Container 。
The key you want to have the pod that will not exit.您希望拥有不会退出的 pod 的键。 Here is an example for you.
这是一个给你的例子。
apiVersion: v1
kind: Pod
metadata:
name: mypod
namespace: mynamespcae
labels:
app: mypod
spec:
containers:
- command:
- bash
- -c
- yes > /dev/null
name: mypod
image: myimage:1
The command yes
will continue to output the string yes
until it is killed.命令
yes
将继续 output 字符串yes
直到它被杀死。 The part > /dev/null
will make sure that you won't have a ton of garbage logs.部分
> /dev/null
将确保您不会有大量的垃圾日志。 Then you can access your pod with these commands.然后,您可以使用这些命令访问您的 pod。
kubectl apply -f my-pod.yaml
kubectl exec -it mypod bash
Remember to remove the pod after you finish all the operations.请记住在完成所有操作后移除 pod。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.