【kubernetes/k8s概念】pod 的yaml解釋
阿新 • • 發佈:2019-01-09
apiVersion: v1
kind: Pod
可以看到由kind、apiVersion、metadata、spec和status等幾個部分組成。
1 kind
kind表明物件。物件(objects):例如Pod、RC、Service、Namespace及Node等
2 apiVersion
表明API的版本號3 metadata
資源物件的元資料定義,是集合類的元素型別,包含一組由不同名稱定義的屬性- namespace:物件所屬的名稱空間,預設為“default”的系統名稱空間
- name:物件的名字,在一個名稱空間中名字應具備唯一性
- uid:系統為每個物件生成的唯一ID
此外,每種物件還應該包含以下幾個重要元資料。
- labels:map標籤,通常用於標籤選擇器(Label Selector),用來匹配目標物件
- annotations:使用者可定義的“註解”,map,被Kubernetes內部程序或者某些外部工具使用,用於儲存和獲取關於該物件的特定元資料。
- resourceVersion:用於識別該資源內部版本號的字串,在用於Watch操作時,可以避免在GET操作和下一次Watch操作之間造成的資訊不一致,客戶端可以用它來判斷資源是否改變。該值應該被客戶端看作不透明,且不做任何修改就返回給服務端。
- creationTimestamp:記錄建立物件時的時間戳
- deletionTimestamp:記錄刪除物件時的時間戳
- selfLink:通過API訪問資源自身的URL,例如一個Pod的link可能是/api/v1/namespaces/ns36aa8455/pods/sc-cluster-test-1-6bc58d44d6-r8hld
metadata:
creationTimestamp: 2018-06-12T03:02:29Z
generateName: sc-cluster-test-1-6bc58d44d6-
labels:
kubeapp: sc-cluster-test-1
pod-template-hash: "2671480082"
name: sc-cluster-test-1-6bc58d44d6-r8hld
namespace: ns36aa8455
ownerReferences:
- apiVersion: extensions/v1beta1
blockOwnerDeletion: true
controller: true
kind: ReplicaSet
name: sc-cluster-test-1-6bc58d44d6
uid: 2d9b9fff-6dec-11e8-9290-005056839655
resourceVersion: "6674931"
selfLink: /api/v1/namespaces/ns36aa8455/pods/sc-cluster-test-1-6bc58d44d6-r8hld
uid: 0b0699db-6ded-11e8-9290-005056839655
4 spec
描述的主體部分都在spec裡給出,持久化到etcd中儲存,系統通過spec的描述來建立或更新物件,以達到使用者期望的狀態
spec:
containers:
- image: 10.12.40.217/paas-k8s/sc-cluster:latest
imagePullPolicy: Always
name: sc-cluster-test-1
ports:
- containerPort: 20888
name: 6f71997b94
protocol: TCP
resources:
limits:
cpu: "1"
memory: 1Gi
requests:
cpu: 500m
memory: 1Gi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /data
name: sc-cluster-test-10
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-jtn4n
readOnly: true
dnsPolicy: ClusterFirst
nodeName: node7
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
volumes:
- hostPath:
path: /data
type: ""
name: sc-cluster-test-10
- name: default-token-jtn4n
secret:
defaultMode: 420
secretName: default-token-jtn4n
5 status
物件在系統中的當前狀態資訊以Pod為例,Pod的status資訊主要包括conditions、containerStatuses、hostIP、phase、podIP、startTime等
- phase:物件所處的生命週期階段,Pending(建立中)Running Active(正在執行中)Terminated(已終結)
- condition:表示條件,由條件型別和狀態值組成,目前僅有一種條件型別Ready,對應的狀態值可以為True、False或Unknown。一個物件可以具備多種condition,而condition的狀態值也可能不斷髮生變化,condition可能附帶一些資訊,例如最後的探測時間或最後的轉變時間。
status:
conditions:
- lastProbeTime: null
lastTransitionTime: 2018-06-12T03:04:52Z
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: 2018-06-12T03:04:53Z
status: "True"
type: Ready
- lastProbeTime: null
lastTransitionTime: 2018-06-12T03:02:29Z
status: "True"
type: PodScheduled
containerStatuses:
- containerID: docker://65bc9886543f835e65be8afb9e7a12772ffd739f9035e33efeb7d3accb53ca54
image: 10.12.40.217/paas-k8s/sc-cluster:latest
imageID: docker-pullable://10.12.40.217/paas-k8s/[email protected]:74e7b431c7bcac48ebfd0ee5b76bb75c10400dbf206f27fe1a0fe2a4cd1888c2
lastState: {}
name: sc-cluster-test-1
ready: true
restartCount: 0
state:
running:
startedAt: 2018-06-12T03:04:53Z
hostIP: 10.12.51.172
phase: Running
podIP: 10.233.100.159
qosClass: Burstable
startTime: 2018-06-12T03:04:52Z