linux - 定义命令和参数 - Pod yaml
问题描述
根据提到的语法,下面是 Pod yaml 使用args
:
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-exec
spec:
containers:
- name: liveness
image: k8s.gcr.io/busybox
resources:
limits:
memory: "64Mi" #64 MB
cpu: "50m" #50 millicpu (.05 cpu or 5% of the cpu)
args:
- /bin/sh
- -c
- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
文档说:If you define args, but do not define a command, the default command is used with your new arguments.
根据文档,参数的默认命令是什么(在上面的 yaml 中)?
解决方案
“默认命令”引用容器映像中设置的命令。如果是您的图像k8s.gcr.io/busybox
--这似乎是/bin/sh
:
$ docker pull k8s.gcr.io/busybox
Using default tag: latest
latest: Pulling from busybox
a3ed95caeb02: Pull complete
138cfc514ce4: Pull complete
Digest: sha256:d8d3bc2c183ed2f9f10e7258f84971202325ee6011ba137112e01e30f206de67
Status: Downloaded newer image for k8s.gcr.io/busybox:latest
k8s.gcr.io/busybox:latest
$ docker image inspect k8s.gcr.io/busybox | jq '.[0] | .Config.Cmd'
[
"/bin/sh"
]
因此,通过显式设置 a pod.spec.containers.command
,您实际上是覆盖了该值。
也可以看看:
$ kubectl explain pod.spec.containers.command
KIND: Pod
VERSION: v1
FIELD: command <[]string>
DESCRIPTION:
Entrypoint array. Not executed within a shell. The docker image's
ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME)
are expanded using the container's environment. If a variable cannot be
resolved, the reference in the input string will be unchanged. The
$(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME).
Escaped references will never be expanded, regardless of whether the
variable exists or not. Cannot be updated. More info:
https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell
在这里阅读更多。
推荐阅读
- angular - 使用服务显示/隐藏组件内的元素
- python - 如何从 pdf 中清除提取的代码,以便以后使用
- sql-server - 如何在 JavaScript 中为 BigQuery 实现 T-SQL CHECKSUM()?
- python - Python外部合并排序运行缓慢
- c - 从二进制分段错误中读取时
- excel - VBA:双变量中缺少前导零
- python - Python 套接字:使用套接字发送 UTF-8
- php - Laravel:获取所有试镜的参赛者及其选票
- angular - 打开带有单选按钮组的 Angular 模态窗口会导致 ExpressionChangedAfterItHasBeenCheckedError
- c++ - 如何找到“使用命名空间标准”的违规用法?