概述

command和args是containers下的两个指令,类似Dockerfile中的ENTRYPONIT和CMD指令。

官方文档地址:https://kubernetes.io/zh-cn/docs/tasks/inject-data-application/define-command-argument-container/

command

command功能同Dockerfile中的ENTRYPONIT指令,用于指定容器启动时要执行的命令。如果不设置command,容器将使用基础镜像中默认的启动命令,也就是ENTRYPONIT指定的启动命令。

可以通过kubectl explain pod.spec.containers.command查看对应的资源信息

示例:

[root@master01 ~]# kubectl explain pod.spec.containers.command
KIND: Pod
VERSION: v1 FIELD: command <[]string> DESCRIPTION:
Entrypoint array. Not executed within a shell. The container 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. Double $$
are reduced to a single $, which allows for escaping the $(VAR_NAME)
syntax: i.e. "$$(VAR_NAME)" will produce the string literal "$(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

args

args功能同Dockerfile中的CMD指令,用于为command指定的命令提供参数。如果command没有指定,则args中的参数将作为基础镜像中默认命令的参数,也就是ENTRYPONIT指令的参数。

可以通过kubectl explain pod.spec.containers.args查看对应的资源信息

示例:

[root@master01 ~]# kubectl explain pod.spec.containers.args
KIND: Pod
VERSION: v1 FIELD: args <[]string> DESCRIPTION:
Arguments to the entrypoint. The container image's CMD 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. Double $$ are reduced to a single $,
which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will
produce the string literal "$(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

示例

# 定义资源清单
[root@master01 ~/pod]# cat command-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: command-demo
labels:
purpose: demonstrate-command
spec:
containers:
- name: command-demo-container
image: debian
command: ["printenv"]
args: ["HOSTNAME", "KUBERNETES_PORT"]
restartPolicy: OnFailure # 创建pod
[root@master01 ~/pod]# kubectl apply -f command-pod.yaml
pod/command-demo created # 查看Pod日志打印信息
[root@master01 ~/pod]# kubectl logs command-demo
command-demo
tcp://10.96.0.1:443

使用注意事项

  • 如果command和args均没有写,那么用Dockerfile的配置。

  • 如果command写了,但args没有写,那么Dockerfile默认的配置会被忽略,执行输入的command

  • 如果command没写,但args写了,那么Dockerfile中配置的ENTRYPOINT的命令会被执行,使用当前args的参数

  • 如果command和args都写了,那么Dockerfile的配置被忽略,执行command并追加上args参数

K8s新手系列之Pod容器中的command和args指令的更多相关文章

  1. k8s集群Job Pod 容器可能因为多种原因失效,想要更加稳定的使用Job负载,有哪些需要注意的地方?

    k8s集群Job Pod 容器可能因为多种原因失效,想要更加稳定的使用Job负载,有哪些需要注意的地方? 面试官:"计数性Job默认完成模式是什么?Indexed模式如何发布自定义索引呢?& ...

  2. 在k8s中将nginx.conf文件内容创建为ConfigMap挂载到pod容器中

    将nginx.conf文件内容创建为ConfigMap user nginx; worker_processes auto; error_log /var/log/nginx/error.log er ...

  3. 使用kuboard界面管理k8s集群时使用ConfigMap挂载挂载到pod容器中,映射成一个文件夹

    将 ConfigMap 作为一个数据卷(在挂载时不指定数据卷内子路径,需要指定ConfigMap的子路径)挂载到容器,此时 ConfigMap 将映射成一个文件夹,每一个 KEY 是文件夹下的文件名, ...

  4. K8s Scheduler 在调度 pod 过程中遗漏部分节点的问题排查

    问题现象 在TKE控制台上新建版本为v1.18.4(详细版本号 < v1.18.4-tke.5)的独立集群,其中,集群的节点信息如下: 有3个master node和1个worker node, ...

  5. k8s 传参给docker env command、args和dockerfile中的entrypoint、cmd之间的关系

    [k8s]args指令案例-彻底理解docker entrypoint     需求: 搞个镜像,可以运行java -jar xxx.jar包,xxx.jar包名称要用参数传 思路1: 打对应运行ja ...

  6. 【JVM故障问题排查心得】「内存诊断系列」Docker容器经常被kill掉,k8s中该节点的pod也被驱赶,怎么分析?

    背景介绍 最近的docker容器经常被kill掉,k8s中该节点的pod也被驱赶. 我有一个在主机中运行的Docker容器(也有在同一主机中运行的其他容器).该Docker容器中的应用程序将会计算数据 ...

  7. CSS 布局实例系列(四)如何实现容器中每一行的子容器数量随着浏览器宽度的变化而变化?

    Hello,小朋友们,还记得我是谁吗?对了,我就是~超威~好啦,言归正传,今天的布局实例是: 实现一个浮动布局,红色容器中每一行的蓝色容器数量随着浏览器宽度的变化而变化,就如下图: 肯定有人心里犯嘀咕 ...

  8. SpringBoot整合shiro系列-SpingBoot是如何将shiroFilter注册到servlet容器中的

    一.先从配置类入手,主要是@Bean了一个ShiroFilterFactoryBean: @Data @Configuration @Slf4j @EnableConfigurationPropert ...

  9. k8s入门系列之guestbook快速部署

    k8s集群以及一些扩展插件已经安装完毕,本篇文章介绍一下如何在k8s集群上快速部署guestbook应用. •实验环境为集群:master(1)+node(4),详细内容参考<k8s入门系列之集 ...

  10. k8s入门系列之扩展组件(一)DNS安装篇

    DNS (domain name system),提供域名解析服务,解决了难于记忆的IP地址问题,以更人性可读可记忆可标识的方式映射对应IP地址. Cluster DNS扩展插件用于支持k8s集群系统 ...

随机推荐

  1. 闲话 6.30 -JL 引理

    参考了 https://spaces.ac.cn/archives/8679/comment-page-1,有一些增删. JL 引理 首先下面需要应用马尔可夫不等式的另一个形式: \[\newcomm ...

  2. Flink Maven项目,依赖配置pom.xml

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  3. DispatcherPriority 枚举

    DispatcherPriority 枚举 ApplicationIdle 2 枚举值为 2. 在应用程序空闲时处理操作. Background 4 枚举值为 4. 在完成所有其他非空闲操作后处理操作 ...

  4. 函数static的作用

    限制作用域和保持状态 ‌函数static的作用主要体现在限制作用域和保持状态两个方面.‌‌1 限制作用域 ‌静态全局变量‌:在全局变量前加上static关键字,该变量就被定义成为一个静态全局变量.这种 ...

  5. ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this

    mysql操作错误: mysql> use mysql;ERROR 1820 (HY000): You must reset your password using ALTER USER sta ...

  6. Typecho弹出find Input author error怎么解决

    大多数报错的起因就是因为,有些模板归档页面的评论功能被阉割掉了 于是导致一些评论验证功能的插件爆这个错误. #解决方法有以下三种 1,编辑这些没有评论功能的页面,高级设置,关闭评论,然后发布文章. 2 ...

  7. 面试题64. 求1+2+…+n

    地址:https://leetcode-cn.com/problems/qiu-12n-lcof/ <?php /** 求 1+2+...+n ,要求不能使用乘除法.for.while.if.e ...

  8. C# async/await使用举例

    1.async/await几点总结 a.被async标记的方法,返回值类型只能为void.Task.Task<T>. b.被async标记的方法,内部可以有await修饰符,表明内部逻辑某 ...

  9. 探秘Transformer系列之(10)--- 自注意力

    探秘Transformer系列之(10)--- 自注意力 目录 探秘Transformer系列之(10)--- 自注意力 0x00 概述 0x01 原理 1.1 设计思路 1.2 输入 1.3 QKV ...

  10. @SpringBootApplication自动配置原理

    @EnableAutoConfiguration 是核心,他会调用一个@Import注解.我们已知Import自动配置得实现是通过创建ImportSelector 接口的实现类并重写里面selectI ...