Pod中spec的字段常用字段及含義
阿新 • • 發佈:2019-03-28
ima 是否 字段 container resource 系統 nta 監聽 host
一、Pod中spec的字段常用字段及含義
1、pod.spec.containers
² spec.containers.name <string> #pod的名稱,必須字段,名稱唯一且對象創建後不可以被修改
² spec.containers.image <string> #鏡像倉庫的路徑/鏡像的名稱:鏡像的標簽
spec.containers.image.imagePullPolicy <string> #鏡像的下載策略。有三種:Always(總是去倉庫下載) ,Never(從不去倉庫下載) , IfNotPresent(如果本地沒有就去倉庫下載) 默認是"IfNotPresent" 但是,如果鏡像的標簽是latest,則總會是"Always,並且對象一旦被創建,這個字段不允許被改變
² spec.containers.ports: #容器公開的端口列表。在這裏公開端口可以為系統提供關於容器使用的網絡連接的額外信息,但主要是提供信息。在這裏不指定端口不會阻止該端口被公開。任何監聽容器內默認的“0.0.0.0”地址的端口都可以從網絡訪問
spec.containers.ports.containerPort #pod暴露的端口,此端口僅是額外的信息,對端口是否被暴露沒有影響
spec.containers.ports.hostPort <integer> #主機上公開的端口
spec.containers.ports.protocol <string> #端口的協議
spec.containers.ports.hostIP <string> #指定要綁定的主機
² spec.containers.command <[]string> #運行的程序,類似於docker中的entrypiont,並且這裏的命令不會運行在shell中,如果沒有這個字段docker鏡像會運行自己entrypiont中的指令
² pod.spec.containers.volumeMounts
pod.spec.containers.volumeMounts.name
pod.spec.containers.volumeMounts.mountPath #可以被容器掛載的存儲卷的路徑,路徑不能包含‘:‘ 符號pod.spec.containers.volumeMounts.subPath #可以被容器掛載的存儲卷的路徑,並且不會覆蓋掛載點中的文件
pod.spec.containers.volumeMounts.readOnly #是否只讀,默認為false
pod.spec.containers.resources
² spec.containers.resources.limits #資源限制
spec.containers.resources.limits.cpu : CPU 上限, 可以短暫超過, 容器也不會被停止
spec.containers.resources.limits.memory : 內存上限, 不可以超過; 如果超過, 容器可能會被終止或調度到其他資源充足的機器上
² spec.containers.resources.requests #資源需求
spec.containers.resources.requests.cpu : CPU 請求, 也是調度 CPU 資源的 依據, 可以超過
spec.containers.resources.requests.memory : 內存請求, 也是調度內存資源 的依據, 可以超過; 但如果超過, 容器可能會在 Node 內存不足時清理
² args:相當於dockerfile裏面的cmd
² command:相當於docker裏面的Entrypoint
如果既沒有指定args,也沒有指定command,那麽會默認使用dockfile的cmd和entrypoint。
如果指定了command,但沒有提供args,那麽就直接運行command。
如果指定了args,但是沒指定command,那麽將使用鏡像中的entrypoint命令,把我們寫的args當做參數傳遞給鏡像中的entrypoint。
如果既用來command,又用了args,那麽鏡像中的cmd和entrypoint將被忽略,而使用K8s提供的command with args。
Pod中spec的字段常用字段及含義