上一章咱們講了,kubelet如何經過計算容器的hash來判斷是否須要升級容器。node
本文主要講如何判斷Pod就地升級完成。nginx
在ContainerStatus中不只有hash filed。還記錄了ImageID filed。docker
// Status represents the status of a container. type Status struct { // ID of the container. ID ContainerID // Name of the container. Name string // Status of the container. State State // Creation time of the container. CreatedAt time.Time // Start time of the container. StartedAt time.Time // Finish time of the container. FinishedAt time.Time // Exit code of the container. ExitCode int // Name of the image, this also includes the tag of the image, // the expected form is "NAME:TAG". Image string // ID of the image. ImageID string // Hash of the container, used for comparison. Hash uint64 // Number of times that the container has been restarted. RestartCount int // A string explains why container is in such a status. Reason string // Message written by the container before exiting (stored in // TerminationMessagePath). Message string }
關於ImageID的更加詳細的講述,你們能夠參考這個系列文章的第一篇。api
咱們任意查看一個Pod的具體信息:app
apiVersion: v1 kind: Pod metadata: annotations: kubernetes.io/psp: eks.privileged creationTimestamp: "2020-07-10T02:33:03Z" generateName: nginx-574b87c764- labels: app: nginx pod-template-hash: 574b87c764 name: nginx-574b87c764-gf4tx namespace: default ownerReferences: - apiVersion: apps/v1 blockOwnerDeletion: true controller: true kind: ReplicaSet name: nginx-574b87c764 uid: c0a0499b-808e-4aa9-a3c3-2ecdb823a19b resourceVersion: "2088142" selfLink: /api/v1/namespaces/default/pods/nginx-574b87c764-gf4tx uid: a5e4d703-3a01-4712-a64a-2814848d9dff spec: containers: - image: nginx:1.14.2 imagePullPolicy: IfNotPresent name: nginx ports: - containerPort: 80 protocol: TCP resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File volumeMounts: - mountPath: /var/run/secrets/kubernetes.io/serviceaccount name: default-token-lzpd4 readOnly: true dnsPolicy: ClusterFirst enableServiceLinks: true nodeName: ip-172-17-186-211.ap-south-1.compute.internal priority: 0 restartPolicy: Always schedulerName: default-scheduler securityContext: {} serviceAccount: default serviceAccountName: default terminationGracePeriodSeconds: 30 tolerations: - effect: NoExecute key: node.kubernetes.io/not-ready operator: Exists tolerationSeconds: 300 - effect: NoExecute key: node.kubernetes.io/unreachable operator: Exists tolerationSeconds: 300 volumes: - name: default-token-lzpd4 secret: defaultMode: 420 secretName: default-token-lzpd4 status: conditions: - lastProbeTime: null lastTransitionTime: "2020-07-10T02:33:03Z" status: "True" type: Initialized - lastProbeTime: null lastTransitionTime: "2020-07-10T02:33:06Z" status: "True" type: Ready - lastProbeTime: null lastTransitionTime: "2020-07-10T02:33:06Z" status: "True" type: ContainersReady - lastProbeTime: null lastTransitionTime: "2020-07-10T02:33:03Z" status: "True" type: PodScheduled containerStatuses: - containerID: docker://918275efc39411f454b7dd8c7f1e3cbd0e6eba00370b0bcaaac0b1b9a5dd868d image: nginx:1.14.2 imageID: docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d lastState: {} name: nginx ready: true restartCount: 0 started: true state: running: startedAt: "2020-07-10T02:33:05Z" hostIP: 172.17.186.211 phase: Running podIP: 172.17.166.134 podIPs: - ip: 172.17.166.134 qosClass: BestEffort startTime: "2020-07-10T02:33:03Z"
如上 imageID: docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
。ui
具體的流程以下:this
至此,關於實現就地升級的幾個關鍵點基本已經講完。spa
就地升級的流程大體以下:rest