type PodStatus struct { Phase PodPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase,casttype=PodPhase"` Conditions []PodCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,2,rep,name=conditions"` Message string`json:"message,omitempty" protobuf:"bytes,3,opt,name=message"` Reason string`json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"` // nominatedNodeName is set only when this pod preempts other pods on the node, but it cannot be // scheduled right away as preemption victims receive their graceful termination periods. // This field does not guarantee that the pod will be scheduled on this node. Scheduler may decide // to place the pod elsewhere if other nodes become available sooner. Scheduler may also decide to // give the resources on this node to a higher priority pod that is created after preemption. // As a result, this field may be different than PodSpec.nodeName when the pod is // scheduled. // +optional NominatedNodeName string`json:"nominatedNodeName,omitempty" protobuf:"bytes,11,opt,name=nominatedNodeName"`
// IP address of the host to which the pod is assigned. Empty if not yet scheduled. // +optional HostIP string`json:"hostIP,omitempty" protobuf:"bytes,5,opt,name=hostIP"` // IP address allocated to the pod. Routable at least within the cluster. // Empty if not yet allocated. // +optional PodIP string`json:"podIP,omitempty" protobuf:"bytes,6,opt,name=podIP"`
// podIPs holds the IP addresses allocated to the pod. If this field is specified, the 0th entry must // match the podIP field. Pods may be allocated at most 1 value for each of IPv4 and IPv6. This list // is empty if no IPs have been allocated yet. // +optional // +patchStrategy=merge // +patchMergeKey=ip PodIPs []PodIP `json:"podIPs,omitempty" protobuf:"bytes,12,rep,name=podIPs" patchStrategy:"merge" patchMergeKey:"ip"`
// RFC 3339 date and time at which the object was acknowledged by the Kubelet. // This is before the Kubelet pulled the container image(s) for the pod. // +optional StartTime *metav1.Time `json:"startTime,omitempty" protobuf:"bytes,7,opt,name=startTime"`
// The list has one entry per init container in the manifest. The most recent successful // init container will have ready = true, the most recently started container will have // startTime set. // More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-and-container-status InitContainerStatuses []ContainerStatus `json:"initContainerStatuses,omitempty" protobuf:"bytes,10,rep,name=initContainerStatuses"`
// The list has one entry per container in the manifest. Each entry is currently the output // of `docker inspect`. // More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-and-container-status // +optional ContainerStatuses []ContainerStatus `json:"containerStatuses,omitempty" protobuf:"bytes,8,rep,name=containerStatuses"` // The Quality of Service (QOS) classification assigned to the pod based on resource requirements // See PodQOSClass type for available QOS classes // More info: https://git.k8s.io/community/contributors/design-proposals/node/resource-qos.md // +optional QOSClass PodQOSClass `json:"qosClass,omitempty" protobuf:"bytes,9,rep,name=qosClass"` // Status for any ephemeral containers that have run in this pod. // This field is alpha-level and is only populated by servers that enable the EphemeralContainers feature. // +optional EphemeralContainerStatuses []ContainerStatus `json:"ephemeralContainerStatuses,omitempty" protobuf:"bytes,13,rep,name=ephemeralContainerStatuses"` }
Pod 的 phase 是 Pod 在其生命周期中的简单宏观概述。该阶段并不是对容器或 Pod 的综合汇总,也不是为了做为综合状态机。Pod Phase的数量和含义是严格指定的。除了本文档中列举的状态外,不应该再假定 Pod 有其他的 phase 值。
下面是 phase 可能的值:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// PodPending means the pod has been accepted by the system, but one or more of the containers // has not been started. This includes time before being bound to a node, as well as time spent // pulling images onto the host. PodPending PodPhase = "Pending" // PodRunning means the pod has been bound to a node and all of the containers have been started. // At least one container is still running or is in the process of being restarted. PodRunning PodPhase = "Running" // PodSucceeded means that all containers in the pod have voluntarily terminated // with a container exit code of 0, and the system is not going to restart any of these containers. PodSucceeded PodPhase = "Succeeded" // PodFailed means that all containers in the pod have terminated, and at least one container has // terminated in a failure (exited with a non-zero exit code or was stopped by the system). PodFailed PodPhase = "Failed" // PodUnknown means that for some reason the state of the pod could not be obtained, typically due // to an error in communicating with the host of the pod. PodUnknown PodPhase = "Unknown"
下图是Pod的生命周期示意图,从图中可以看到Pod状态的变化。
Pod Condition
PodStatus 对象中包含一个 PodCondition 数组。 PodCondition 数组的每个元素都有一个 type 字段和一个 status 字段
type 字段是字符串,可能的值有 PodScheduled、Ready、Initialized、Unschedulable和ContainersReady
status 字段是一个字符串,可能的值有 True、False 和 Unknown。
1 2 3 4 5 6 7 8
type PodCondition struct { Type PodConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=PodConditionType"` Status ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=ConditionStatus"` LastProbeTime metav1.Time `json:"lastProbeTime,omitempty" protobuf:"bytes,3,opt,name=lastProbeTime"` LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"` Reason string`json:"reason,omitempty" protobuf:"bytes,5,opt,name=reason"` Message string`json:"message,omitempty" protobuf:"bytes,6,opt,name=message"` }
Condition Type
1 2 3 4 5 6 7 8 9
// ContainersReady indicates whether all containers in the pod are ready. ContainersReady PodConditionType = "ContainersReady" // PodInitialized means that all init containers in the pod have started successfully. PodInitialized PodConditionType = "Initialized" // PodReady means the pod is able to service requests and should be added to the // load balancing pools of all matching services. PodReady PodConditionType = "Ready" // PodScheduled represents status of the scheduling process for this pod. PodScheduled PodConditionType = "PodScheduled"
apiVersion:v1 kind:Pod metadata: labels: test:liveness name:liveness-http spec: containers: -args: -/server image:k8s.gcr.io/liveness livenessProbe: httpGet: # when "host" is not defined, "PodIP" will be used # host: my-host # when "scheme" is not defined, "HTTP" scheme will be used. Only "HTTP" and "HTTPS" are allowed # scheme: HTTPS path:/healthz port:8080 httpHeaders: -name:X-Custom-Header value:Awesome initialDelaySeconds:15 timeoutSeconds:1 name:liveness
var ErrCrashLoopBackOff = errors.New("CrashLoopBackOff")
var ( // ErrContainerNotFound returned when a container in the given pod with the // given container name was not found, amongst those managed by the kubelet. ErrContainerNotFound = errors.New("no matching container") )