K8s Pod容器中的command和args指令詳解
概述
command和args是containers下的兩個(gè)指令,類似Dockerfile中的ENTRYPONIT和CMD指令。
官方文檔地址:https://kubernetes.io/zh-cn/docs/tasks/inject-data-application/define-command-argument-container/
command
command功能同Dockerfile中的ENTRYPONIT指令,用于指定容器啟動(dòng)時(shí)要執(zhí)行的命令。如果不設(shè)置command,容器將使用基礎(chǔ)鏡像中默認(rèn)的啟動(dòng)命令,也就是ENTRYPONIT指定的啟動(dòng)命令。
可以通過(guò)kubectl explain pod.spec.containers.command
查看對(duì)應(yīng)的資源信息
示例:
[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指定的命令提供參數(shù)。如果command沒(méi)有指定,則args中的參數(shù)將作為基礎(chǔ)鏡像中默認(rèn)命令的參數(shù),也就是ENTRYPONIT指令的參數(shù)。
可以通過(guò)kubectl explain pod.spec.containers.args
查看對(duì)應(yīng)的資源信息
示例:
[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 # 創(chuàng)建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
使用注意事項(xiàng)
如果command和args均沒(méi)有寫(xiě),那么用Dockerfile的配置。
如果command寫(xiě)了,但args沒(méi)有寫(xiě),那么Dockerfile默認(rèn)的配置會(huì)被忽略,執(zhí)行輸入的command
如果command沒(méi)寫(xiě),但args寫(xiě)了,那么Dockerfile中配置的ENTRYPOINT的命令會(huì)被執(zhí)行,使用當(dāng)前args的參數(shù)
如果command和args都寫(xiě)了,那么Dockerfile的配置被忽略,執(zhí)行command并追加上args參數(shù)
到此這篇關(guān)于K8s新手系列之Pod容器中的command和args指令的文章就介紹到這了,更多相關(guān)K8s Pod中command和args指令內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- k8s強(qiáng)制刪除一個(gè)Pod的詳細(xì)步驟
- K8s學(xué)習(xí)之Pod的定義及詳細(xì)資源調(diào)用案例
- K8S如何利用Prometheus監(jiān)控pod的實(shí)時(shí)數(shù)據(jù)指標(biāo)
- K8S內(nèi)部pod之間相互調(diào)用案例以及詳解
- K8S中Pod重啟策略及重啟可能原因詳細(xì)講解
- k8s中如何實(shí)現(xiàn)pod自動(dòng)擴(kuò)縮容詳解
- K8s實(shí)戰(zhàn)教程之容器和?Pods資源分配問(wèn)題
- k8s查看pod日志的幾種實(shí)用方法匯總
- k8s監(jiān)控?cái)?shù)據(jù)組件Pod自動(dòng)化進(jìn)行擴(kuò)縮容HPA
相關(guān)文章
k8s自動(dòng)化安裝腳本(二進(jìn)制)的操作步驟
Kubernetes?k8s安裝腳本,非常好用,下面這篇文章主要給大家介紹了關(guān)于k8s自動(dòng)化安裝腳本(二進(jìn)制)的操作步驟,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09關(guān)于k8s?使用?Service?控制器對(duì)外暴露服務(wù)的問(wèn)題
這篇文章主要介紹了k8s使用Service控制器對(duì)外暴露服務(wù),包括部署deploy,部署?service及查看?service?和?pod?的關(guān)系,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-03-03kubernetes部署dashboard及應(yīng)用小結(jié)
Dashboard?是基于網(wǎng)頁(yè)的?Kubernetes?用戶界面,可以對(duì)?Deployment?實(shí)現(xiàn)彈性伸縮、發(fā)起滾動(dòng)升級(jí)、重啟?Pod?或者使用向?qū)?chuàng)建新的應(yīng)用,這篇文章主要介紹了kubernetes部署dashboard,需要的朋友可以參考下2024-06-06MinIO分布式文件存儲(chǔ)(從入門(mén)到飛翔)
MinIO是一款高性能的分布式對(duì)象存儲(chǔ)系統(tǒng),兼容Amazon S3協(xié)議,具有輕量級(jí)、易部署、高可用和可擴(kuò)展性等優(yōu)勢(shì),它通過(guò)糾刪碼技術(shù)實(shí)現(xiàn)數(shù)據(jù)冗余與高容錯(cuò)性,適用于私有云存儲(chǔ)、大數(shù)據(jù)分析和靜態(tài)資源托管等場(chǎng)景,本文介紹MinIO分布式文件存儲(chǔ)的相關(guān)知識(shí),感興趣的朋友一起看看吧2025-03-03