美文网首页
Kubernetes学习笔记--对Pod执行Shell操作

Kubernetes学习笔记--对Pod执行Shell操作

作者: 木子一酱 | 来源:发表于2020-10-26 17:44 被阅读0次

如创建 Pod:

    kubectl create -f https://k8s.io/examples/application/shell-demo.yaml

获取pod:

        kubectl get pod shell-demo

1. 使用shell进入pod:

        kubectl  exec  -it shell-demo -- /bin/bash

进入pod后就可以执行命令。

2. 运行单个命令打印环境运行容器中的变量::

kubectl exec  shell-demo  env

运行其他命令:

kubectl exec shell-demo ls /

kubectl exec shell-demo cat /proc/1/mounts

4. 当 Pod 包含多个容器:

如果 Pod 有多个容器,--container 或者 -c 可以在 kubectl exec 命令中指定容器。 例如,名为 my-pod 的容器,该 Pod 有两个容器分别为 main-app 和 healper-app。 下面的命令将会打开一个 shell 访问 main-app 容器

        kubectlexec-it my-pod --container main-app -- /bin/bash

相关文章

网友评论

      本文标题:Kubernetes学习笔记--对Pod执行Shell操作

      本文链接:https://www.haomeiwen.com/subject/dnaqmktx.html