version 字符串
- 這裏是指k8s API的版本,可以用kubectl api-versions 命令查看, 目前都是v1
kind 字符串
- 這裏指的是yaml文件定義的資源類型和角色,例如:pod
metadata 對象
- 元數據對象,固定值就寫metadata
metadata.name 字符串
- 元數據對象的名字,這裏由我們編寫,比如命名pod的名字
metadata.namespace 字符串
- 元數據對象的命名空間,由我們自身定義
spec 對象
- 詳細定義對象,固定值就寫spec
spec.containers[].name 字符串
- 這裏定義容器名字
spec.containers[].image 字符串
- 這裏定義要用到的鏡像名稱
spec.containers[].imagePullPlicy 字符串
- 定義鏡像拉取策略,默認是Always
- Always - 每次都嘗試去拉鏡像
- Never - 只使用本地鏡像
- IfNotPresent - 如果本地沒有就拉鏡像
spec.containers[].command[] 數組
- 指定容器啓動命令,不指定的情況下,默認使用鏡像內部的啓動命令
spec.containers[].args[] 數組
- 指定容器啓動命令參數,例如--name等
spec.containers[].workingDir 字符串
- 指定容器的工作目錄,進入容器之後默認的工作目錄
spec.cotainers[].volumeMounts[] 數組
- 指定容器內部的存儲卷配置
spec.containers[].volumeMouts[].name 字符串
- 指定可以被掛載的存儲卷名稱
spec.containers[].volumeMounts[].mountPath 字符串
- 指定可以被掛載的存儲卷路徑
spec.containers[].volumeMounts[].readOnly 字符串
- 設置存儲卷路徑的讀寫模式,true或者false,默認爲讀寫模式
spec.containers[].ports[] 數組
- 指定容器需要用到的端口列表
spec.containers[].ports[].name 字符串
- 指定端口名稱
spec.cotainers[].ports[].containerPort 字符串
- 指定容器需要監聽的端口
spec.containers[].ports[].hostPort 字符串
- 指定容器所在主機需要監聽的端口號,默認跟上面containerPort相同,注意設置hostPort同一臺主機無法啓動該容器的相同副本,因爲主機端口號不能相同,這樣會衝突
spec.containers[].ports[].protocol 字符串
- 指定端口協議,支持TCP和UDP,默認值爲TCP
spec.containers[].env[] 數組
- 指定容器運行前設置的環境變量列表
spec.containers[].env[].name 字符串
- 指定環境變量
spec.containers[].env[].value 字符串
- 指定環境變量值
spec.containers[].resources 對象
- 指定資源限制和資源請求的值,這裏開始就是設置容器的資源上限
spec.containers[].resources.limits 對象
- 指定設置容器運行時資源的運行上限
spec.containers[].resource.limits.cpu 字符串
- 指定CPU的限制,單位爲core數,將用於docker run --cpu-shares參數
spec.containers[].limits.memory 字符串
- 指定MEM內存的限制,單位爲MIB,GIB
spec.containers[].requests 對象
- 指定容器啓動和調度的限制設置
spec.containers[].requests.cpu 字符串
- CPU請求,單位爲core數,容器啓動時初次化可用數量
spec.containers[].requests.memory 字符串
- 內存請求,單位爲MIB,Gib容器啓動的初次化可用數量