Pod

简要概述

staging/src/k8s.io/api/core/v1/types.go

查看官方介绍

其中数据结构主要由以下四部分组成:

  1. 存储卷 Pod Volume
  2. 容器组 Pod Container
  3. 容器安全 Pod Security
  4. 亲和性与污点 Pod Affinity

常用指令

TODO;

配置示例

  • 通过 kubectl 创建

生成可运行的 yaml 内容

kubectl run busybox \
    --namespace=default \
    --image=registry.cn-hangzhou.aliyuncs.com/opsaid/busybox:1.35.0 \
    --dry-run=client \
    -o yaml \
    --command -- /bin/sh -c sleep 3600
  • 通过 yaml 创建
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: busybox
  name: busybox
  namespace: default
spec:
  containers:
  - command:
    - /bin/sh
    - -c
    - sleep
    - "3600"
    image: registry.cn-hangzhou.aliyuncs.com/opsaid/busybox:1.35.0
    name: busybox
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always

数据结构

Pod

// Pod is a collection of containers that can run on a host. This resource is created
// by clients and scheduled onto hosts.
type Pod struct {
    metav1.TypeMeta `json:",inline"`
    // Standard object's metadata.
    // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    // +optional
    metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

    // Specification of the desired behavior of the pod.
    // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
    // +optional
    Spec PodSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`

    // Most recently observed status of the pod.
    // This data may not be up to date.
    // Populated by the system.
    // Read-only.
    // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
    // +optional
    Status PodStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}

PodSpec

// PodSpec is a description of a pod.
type PodSpec struct {
    // List of volumes that can be mounted by containers belonging to the pod.
    // More info: https://kubernetes.io/docs/concepts/storage/volumes
    // +optional
    // +patchMergeKey=name
    // +patchStrategy=merge,retainKeys
    Volumes []Volume `json:"volumes,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name" protobuf:"bytes,1,rep,name=volumes"`
    // List of initialization containers belonging to the pod.
    // Init containers are executed in order prior to containers being started. If any
    // init container fails, the pod is considered to have failed and is handled according
    // to its restartPolicy. The name for an init container or normal container must be
    // unique among all containers.
    // Init containers may not have Lifecycle actions, Readiness probes, Liveness probes, or Startup probes.
    // The resourceRequirements of an init container are taken into account during scheduling
    // by finding the highest request/limit for each resource type, and then using the max of
    // of that value or the sum of the normal containers. Limits are applied to init containers
    // in a similar fashion.
    // Init containers cannot currently be added or removed.
    // Cannot be updated.
    // More info: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
    // +patchMergeKey=name
    // +patchStrategy=merge
    InitContainers []Container `json:"initContainers,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,20,rep,name=initContainers"`
    // List of containers belonging to the pod.
    // Containers cannot currently be added or removed.
    // There must be at least one container in a Pod.
    // Cannot be updated.
    // +patchMergeKey=name
    // +patchStrategy=merge
    Containers []Container `json:"containers" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,2,rep,name=containers"`
    // List of ephemeral containers run in this pod. Ephemeral containers may be run in an existing
    // pod to perform user-initiated actions such as debugging. This list cannot be specified when
    // creating a pod, and it cannot be modified by updating the pod spec. In order to add an
    // ephemeral container to an existing pod, use the pod's ephemeralcontainers subresource.
    // This field is alpha-level and is only honored by servers that enable the EphemeralContainers feature.
    // +optional
    // +patchMergeKey=name
    // +patchStrategy=merge
    EphemeralContainers []EphemeralContainer `json:"ephemeralContainers,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,34,rep,name=ephemeralContainers"`
    // Restart policy for all containers within the pod.
    // One of Always, OnFailure, Never.
    // Default to Always.
    // More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy
    // +optional
    RestartPolicy RestartPolicy `json:"restartPolicy,omitempty" protobuf:"bytes,3,opt,name=restartPolicy,casttype=RestartPolicy"`
    // Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request.
    // Value must be non-negative integer. The value zero indicates stop immediately via
    // the kill signal (no opportunity to shut down).
    // If this value is nil, the default grace period will be used instead.
    // The grace period is the duration in seconds after the processes running in the pod are sent
    // a termination signal and the time when the processes are forcibly halted with a kill signal.
    // Set this value longer than the expected cleanup time for your process.
    // Defaults to 30 seconds.
    // +optional
    TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
    // Optional duration in seconds the pod may be active on the node relative to
    // StartTime before the system will actively try to mark it failed and kill associated containers.
    // Value must be a positive integer.
    // +optional
    ActiveDeadlineSeconds *int64 `json:"activeDeadlineSeconds,omitempty" protobuf:"varint,5,opt,name=activeDeadlineSeconds"`
    // Set DNS policy for the pod.
    // Defaults to "ClusterFirst".
    // Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'.
    // DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy.
    // To have DNS options set along with hostNetwork, you have to specify DNS policy
    // explicitly to 'ClusterFirstWithHostNet'.
    // +optional
    DNSPolicy DNSPolicy `json:"dnsPolicy,omitempty" protobuf:"bytes,6,opt,name=dnsPolicy,casttype=DNSPolicy"`
    // NodeSelector is a selector which must be true for the pod to fit on a node.
    // Selector which must match a node's labels for the pod to be scheduled on that node.
    // More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
    // +optional
    // +mapType=atomic
    NodeSelector map[string]string `json:"nodeSelector,omitempty" protobuf:"bytes,7,rep,name=nodeSelector"`

    // ServiceAccountName is the name of the ServiceAccount to use to run this pod.
    // More info: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
    // +optional
    ServiceAccountName string `json:"serviceAccountName,omitempty" protobuf:"bytes,8,opt,name=serviceAccountName"`
    // DeprecatedServiceAccount is a depreciated alias for ServiceAccountName.
    // Deprecated: Use serviceAccountName instead.
    // +k8s:conversion-gen=false
    // +optional
    DeprecatedServiceAccount string `json:"serviceAccount,omitempty" protobuf:"bytes,9,opt,name=serviceAccount"`
    // AutomountServiceAccountToken indicates whether a service account token should be automatically mounted.
    // +optional
    AutomountServiceAccountToken *bool `json:"automountServiceAccountToken,omitempty" protobuf:"varint,21,opt,name=automountServiceAccountToken"`

    // NodeName is a request to schedule this pod onto a specific node. If it is non-empty,
    // the scheduler simply schedules this pod onto that node, assuming that it fits resource
    // requirements.
    // +optional
    NodeName string `json:"nodeName,omitempty" protobuf:"bytes,10,opt,name=nodeName"`
    // Host networking requested for this pod. Use the host's network namespace.
    // If this option is set, the ports that will be used must be specified.
    // Default to false.
    // +k8s:conversion-gen=false
    // +optional
    HostNetwork bool `json:"hostNetwork,omitempty" protobuf:"varint,11,opt,name=hostNetwork"`
    // Use the host's pid namespace.
    // Optional: Default to false.
    // +k8s:conversion-gen=false
    // +optional
    HostPID bool `json:"hostPID,omitempty" protobuf:"varint,12,opt,name=hostPID"`
    // Use the host's ipc namespace.
    // Optional: Default to false.
    // +k8s:conversion-gen=false
    // +optional
    HostIPC bool `json:"hostIPC,omitempty" protobuf:"varint,13,opt,name=hostIPC"`
    // Share a single process namespace between all of the containers in a pod.
    // When this is set containers will be able to view and signal processes from other containers
    // in the same pod, and the first process in each container will not be assigned PID 1.
    // HostPID and ShareProcessNamespace cannot both be set.
    // Optional: Default to false.
    // +k8s:conversion-gen=false
    // +optional
    ShareProcessNamespace *bool `json:"shareProcessNamespace,omitempty" protobuf:"varint,27,opt,name=shareProcessNamespace"`
    // SecurityContext holds pod-level security attributes and common container settings.
    // Optional: Defaults to empty.  See type description for default values of each field.
    // +optional
    SecurityContext *PodSecurityContext `json:"securityContext,omitempty" protobuf:"bytes,14,opt,name=securityContext"`
    // ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images used by this PodSpec.
    // If specified, these secrets will be passed to individual puller implementations for them to use. For example,
    // in the case of docker, only DockerConfig type secrets are honored.
    // More info: https://kubernetes.io/docs/concepts/containers/images#specifying-imagepullsecrets-on-a-pod
    // +optional
    // +patchMergeKey=name
    // +patchStrategy=merge
    ImagePullSecrets []LocalObjectReference `json:"imagePullSecrets,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,15,rep,name=imagePullSecrets"`
    // Specifies the hostname of the Pod
    // If not specified, the pod's hostname will be set to a system-defined value.
    // +optional
    Hostname string `json:"hostname,omitempty" protobuf:"bytes,16,opt,name=hostname"`
    // If specified, the fully qualified Pod hostname will be "<hostname>.<subdomain>.<pod namespace>.svc.<cluster domain>".
    // If not specified, the pod will not have a domainname at all.
    // +optional
    Subdomain string `json:"subdomain,omitempty" protobuf:"bytes,17,opt,name=subdomain"`
    // If specified, the pod's scheduling constraints
    // +optional
    Affinity *Affinity `json:"affinity,omitempty" protobuf:"bytes,18,opt,name=affinity"`
    // If specified, the pod will be dispatched by specified scheduler.
    // If not specified, the pod will be dispatched by default scheduler.
    // +optional
    SchedulerName string `json:"schedulerName,omitempty" protobuf:"bytes,19,opt,name=schedulerName"`
    // If specified, the pod's tolerations.
    // +optional
    Tolerations []Toleration `json:"tolerations,omitempty" protobuf:"bytes,22,opt,name=tolerations"`
    // HostAliases is an optional list of hosts and IPs that will be injected into the pod's hosts
    // file if specified. This is only valid for non-hostNetwork pods.
    // +optional
    // +patchMergeKey=ip
    // +patchStrategy=merge
    HostAliases []HostAlias `json:"hostAliases,omitempty" patchStrategy:"merge" patchMergeKey:"ip" protobuf:"bytes,23,rep,name=hostAliases"`
    // If specified, indicates the pod's priority. "system-node-critical" and
    // "system-cluster-critical" are two special keywords which indicate the
    // highest priorities with the former being the highest priority. Any other
    // name must be defined by creating a PriorityClass object with that name.
    // If not specified, the pod priority will be default or zero if there is no
    // default.
    // +optional
    PriorityClassName string `json:"priorityClassName,omitempty" protobuf:"bytes,24,opt,name=priorityClassName"`
    // The priority value. Various system components use this field to find the
    // priority of the pod. When Priority Admission Controller is enabled, it
    // prevents users from setting this field. The admission controller populates
    // this field from PriorityClassName.
    // The higher the value, the higher the priority.
    // +optional
    Priority *int32 `json:"priority,omitempty" protobuf:"bytes,25,opt,name=priority"`
    // Specifies the DNS parameters of a pod.
    // Parameters specified here will be merged to the generated DNS
    // configuration based on DNSPolicy.
    // +optional
    DNSConfig *PodDNSConfig `json:"dnsConfig,omitempty" protobuf:"bytes,26,opt,name=dnsConfig"`
    // If specified, all readiness gates will be evaluated for pod readiness.
    // A pod is ready when all its containers are ready AND
    // all conditions specified in the readiness gates have status equal to "True"
    // More info: https://git.k8s.io/enhancements/keps/sig-network/580-pod-readiness-gates
    // +optional
    ReadinessGates []PodReadinessGate `json:"readinessGates,omitempty" protobuf:"bytes,28,opt,name=readinessGates"`
    // RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used
    // to run this pod.  If no RuntimeClass resource matches the named class, the pod will not be run.
    // If unset or empty, the "legacy" RuntimeClass will be used, which is an implicit class with an
    // empty definition that uses the default runtime handler.
    // More info: https://git.k8s.io/enhancements/keps/sig-node/585-runtime-class
    // This is a beta feature as of Kubernetes v1.14.
    // +optional
    RuntimeClassName *string `json:"runtimeClassName,omitempty" protobuf:"bytes,29,opt,name=runtimeClassName"`
    // EnableServiceLinks indicates whether information about services should be injected into pod's
    // environment variables, matching the syntax of Docker links.
    // Optional: Defaults to true.
    // +optional
    EnableServiceLinks *bool `json:"enableServiceLinks,omitempty" protobuf:"varint,30,opt,name=enableServiceLinks"`
    // PreemptionPolicy is the Policy for preempting pods with lower priority.
    // One of Never, PreemptLowerPriority.
    // Defaults to PreemptLowerPriority if unset.
    // This field is beta-level, gated by the NonPreemptingPriority feature-gate.
    // +optional
    PreemptionPolicy *PreemptionPolicy `json:"preemptionPolicy,omitempty" protobuf:"bytes,31,opt,name=preemptionPolicy"`
    // Overhead represents the resource overhead associated with running a pod for a given RuntimeClass.
    // This field will be autopopulated at admission time by the RuntimeClass admission controller. If
    // the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests.
    // The RuntimeClass admission controller will reject Pod create requests which have the overhead already
    // set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value
    // defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero.
    // More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md
    // This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.
    // +optional
    Overhead ResourceList `json:"overhead,omitempty" protobuf:"bytes,32,opt,name=overhead"`
    // TopologySpreadConstraints describes how a group of pods ought to spread across topology
    // domains. Scheduler will schedule pods in a way which abides by the constraints.
    // All topologySpreadConstraints are ANDed.
    // +optional
    // +patchMergeKey=topologyKey
    // +patchStrategy=merge
    // +listType=map
    // +listMapKey=topologyKey
    // +listMapKey=whenUnsatisfiable
    TopologySpreadConstraints []TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty" patchStrategy:"merge" patchMergeKey:"topologyKey" protobuf:"bytes,33,opt,name=topologySpreadConstraints"`
    // If true the pod's hostname will be configured as the pod's FQDN, rather than the leaf name (the default).
    // In Linux containers, this means setting the FQDN in the hostname field of the kernel (the nodename field of struct utsname).
    // In Windows containers, this means setting the registry value of hostname for the registry key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters to FQDN.
    // If a pod does not have FQDN, this has no effect.
    // Default to false.
    // +optional
    SetHostnameAsFQDN *bool `json:"setHostnameAsFQDN,omitempty" protobuf:"varint,35,opt,name=setHostnameAsFQDN"`
}

Volume

参考 Pod Volume 数据结构。

Container

参考 Pod Container 数据结构。

EphemeralContainer

// An EphemeralContainer is a container that may be added temporarily to an existing pod for
// user-initiated activities such as debugging. Ephemeral containers have no resource or
// scheduling guarantees, and they will not be restarted when they exit or when a pod is
// removed or restarted. If an ephemeral container causes a pod to exceed its resource
// allocation, the pod may be evicted.
// Ephemeral containers may not be added by directly updating the pod spec. They must be added
// via the pod's ephemeralcontainers subresource, and they will appear in the pod spec
// once added.
// This is an alpha feature enabled by the EphemeralContainers feature flag.
type EphemeralContainer struct {
    // Ephemeral containers have all of the fields of Container, plus additional fields
    // specific to ephemeral containers. Fields in common with Container are in the
    // following inlined struct so than an EphemeralContainer may easily be converted
    // to a Container.
    EphemeralContainerCommon `json:",inline" protobuf:"bytes,1,req"`

    // If set, the name of the container from PodSpec that this ephemeral container targets.
    // The ephemeral container will be run in the namespaces (IPC, PID, etc) of this container.
    // If not set then the ephemeral container is run in whatever namespaces are shared
    // for the pod. Note that the container runtime must support this feature.
    // +optional
    TargetContainerName string `json:"targetContainerName,omitempty" protobuf:"bytes,2,opt,name=targetContainerName"`
}

RestartPolicy

// RestartPolicy describes how the container should be restarted.
// Only one of the following restart policies may be specified.
// If none of the following policies is specified, the default one
// is RestartPolicyAlways.
type RestartPolicy string

const (
    RestartPolicyAlways    RestartPolicy = "Always"
    RestartPolicyOnFailure RestartPolicy = "OnFailure"
    RestartPolicyNever     RestartPolicy = "Never"
)

DNSPolicy

// DNSPolicy defines how a pod's DNS will be configured.
type DNSPolicy string

const (
    // DNSClusterFirstWithHostNet indicates that the pod should use cluster DNS
    // first, if it is available, then fall back on the default
    // (as determined by kubelet) DNS settings.
    DNSClusterFirstWithHostNet DNSPolicy = "ClusterFirstWithHostNet"

    // DNSClusterFirst indicates that the pod should use cluster DNS
    // first unless hostNetwork is true, if it is available, then
    // fall back on the default (as determined by kubelet) DNS settings.
    DNSClusterFirst DNSPolicy = "ClusterFirst"

    // DNSDefault indicates that the pod should use the default (as
    // determined by kubelet) DNS settings.
    DNSDefault DNSPolicy = "Default"

    // DNSNone indicates that the pod should use empty DNS settings. DNS
    // parameters such as nameservers and search paths should be defined via
    // DNSConfig.
    DNSNone DNSPolicy = "None"
)

PodSecurityContext

参考 Pod Security 数据结构。

LocalObjectReference

// LocalObjectReference contains enough information to let you locate the
// referenced object inside the same namespace.
// +structType=atomic
type LocalObjectReference struct {
    // Name of the referent.
    // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
    // TODO: Add other useful fields. apiVersion, kind, uid?
    // +optional
    Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
}

Affinity

参考 Pod Affinity 数据结构。

Toleration

参考 Pod Affinity 数据结构。

HostAlias

// HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the
// pod's hosts file.
type HostAlias struct {
    // IP address of the host file entry.
    IP string `json:"ip,omitempty" protobuf:"bytes,1,opt,name=ip"`
    // Hostnames for the above IP address.
    Hostnames []string `json:"hostnames,omitempty" protobuf:"bytes,2,rep,name=hostnames"`
}

PodDNSConfig

// PodDNSConfig defines the DNS parameters of a pod in addition to
// those generated from DNSPolicy.
type PodDNSConfig struct {
    // A list of DNS name server IP addresses.
    // This will be appended to the base nameservers generated from DNSPolicy.
    // Duplicated nameservers will be removed.
    // +optional
    Nameservers []string `json:"nameservers,omitempty" protobuf:"bytes,1,rep,name=nameservers"`
    // A list of DNS search domains for host-name lookup.
    // This will be appended to the base search paths generated from DNSPolicy.
    // Duplicated search paths will be removed.
    // +optional
    Searches []string `json:"searches,omitempty" protobuf:"bytes,2,rep,name=searches"`
    // A list of DNS resolver options.
    // This will be merged with the base options generated from DNSPolicy.
    // Duplicated entries will be removed. Resolution options given in Options
    // will override those that appear in the base DNSPolicy.
    // +optional
    Options []PodDNSConfigOption `json:"options,omitempty" protobuf:"bytes,3,rep,name=options"`
}

// PodDNSConfigOption defines DNS resolver options of a pod.
type PodDNSConfigOption struct {
    // Required.
    Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
    // +optional
    Value *string `json:"value,omitempty" protobuf:"bytes,2,opt,name=value"`
}

PodConditionType

// PodConditionType is a valid value for PodCondition.Type
type PodConditionType string

// These are valid conditions of pod.
const (
    // 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"
)

PodReadinessGate

// PodReadinessGate contains the reference to a pod condition
type PodReadinessGate struct {
    // ConditionType refers to a condition in the pod's condition list with matching type.
    ConditionType PodConditionType `json:"conditionType" protobuf:"bytes,1,opt,name=conditionType,casttype=PodConditionType"`
}

PreemptionPolicy

// PreemptionPolicy describes a policy for if/when to preempt a pod.
type PreemptionPolicy string

const (
    // PreemptLowerPriority means that pod can preempt other pods with lower priority.
    PreemptLowerPriority PreemptionPolicy = "PreemptLowerPriority"
    // PreemptNever means that pod never preempts other pods with lower priority.
    PreemptNever PreemptionPolicy = "Never"
)

ResourceList

// ResourceName is the name identifying various resources in a ResourceList.
type ResourceName string

// Resource names must be not more than 63 characters, consisting of upper- or lower-case alphanumeric characters,
// with the -, _, and . characters allowed anywhere, except the first or last character.
// The default convention, matching that for annotations, is to use lower-case names, with dashes, rather than
// camel case, separating compound words.
// Fully-qualified resource typenames are constructed from a DNS-style subdomain, followed by a slash `/` and a name.
const (
    // CPU, in cores. (500m = .5 cores)
    ResourceCPU ResourceName = "cpu"
    // Memory, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
    ResourceMemory ResourceName = "memory"
    // Volume size, in bytes (e,g. 5Gi = 5GiB = 5 * 1024 * 1024 * 1024)
    ResourceStorage ResourceName = "storage"
    // Local ephemeral storage, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024)
    // The resource name for ResourceEphemeralStorage is alpha and it can change across releases.
    ResourceEphemeralStorage ResourceName = "ephemeral-storage"
)

const (
    // Default namespace prefix.
    ResourceDefaultNamespacePrefix = "kubernetes.io/"
    // Name prefix for huge page resources (alpha).
    ResourceHugePagesPrefix = "hugepages-"
    // Name prefix for storage resource limits
    ResourceAttachableVolumesPrefix = "attachable-volumes-"
)

// ResourceList is a set of (resource name, quantity) pairs.
type ResourceList map[ResourceName]resource.Quantity

TopologySpreadConstraint

type UnsatisfiableConstraintAction string

const (
    // DoNotSchedule instructs the scheduler not to schedule the pod
    // when constraints are not satisfied.
    DoNotSchedule UnsatisfiableConstraintAction = "DoNotSchedule"
    // ScheduleAnyway instructs the scheduler to schedule the pod
    // even if constraints are not satisfied.
    ScheduleAnyway UnsatisfiableConstraintAction = "ScheduleAnyway"
)
// TopologySpreadConstraint specifies how to spread matching pods among the given topology.
type TopologySpreadConstraint struct {
    // MaxSkew describes the degree to which pods may be unevenly distributed.
    // When `whenUnsatisfiable=DoNotSchedule`, it is the maximum permitted difference
    // between the number of matching pods in the target topology and the global minimum.
    // For example, in a 3-zone cluster, MaxSkew is set to 1, and pods with the same
    // labelSelector spread as 1/1/0:
    // +-------+-------+-------+
    // | zone1 | zone2 | zone3 |
    // +-------+-------+-------+
    // |   P   |   P   |       |
    // +-------+-------+-------+
    // - if MaxSkew is 1, incoming pod can only be scheduled to zone3 to become 1/1/1;
    // scheduling it onto zone1(zone2) would make the ActualSkew(2-0) on zone1(zone2)
    // violate MaxSkew(1).
    // - if MaxSkew is 2, incoming pod can be scheduled onto any zone.
    // When `whenUnsatisfiable=ScheduleAnyway`, it is used to give higher precedence
    // to topologies that satisfy it.
    // It's a required field. Default value is 1 and 0 is not allowed.
    MaxSkew int32 `json:"maxSkew" protobuf:"varint,1,opt,name=maxSkew"`
    // TopologyKey is the key of node labels. Nodes that have a label with this key
    // and identical values are considered to be in the same topology.
    // We consider each <key, value> as a "bucket", and try to put balanced number
    // of pods into each bucket.
    // It's a required field.
    TopologyKey string `json:"topologyKey" protobuf:"bytes,2,opt,name=topologyKey"`
    // WhenUnsatisfiable indicates how to deal with a pod if it doesn't satisfy
    // the spread constraint.
    // - DoNotSchedule (default) tells the scheduler not to schedule it.
    // - ScheduleAnyway tells the scheduler to schedule the pod in any location,
    //   but giving higher precedence to topologies that would help reduce the
    //   skew.
    // A constraint is considered "Unsatisfiable" for an incoming pod
    // if and only if every possible node assigment for that pod would violate
    // "MaxSkew" on some topology.
    // For example, in a 3-zone cluster, MaxSkew is set to 1, and pods with the same
    // labelSelector spread as 3/1/1:
    // +-------+-------+-------+
    // | zone1 | zone2 | zone3 |
    // +-------+-------+-------+
    // | P P P |   P   |   P   |
    // +-------+-------+-------+
    // If WhenUnsatisfiable is set to DoNotSchedule, incoming pod can only be scheduled
    // to zone2(zone3) to become 3/2/1(3/1/2) as ActualSkew(2-1) on zone2(zone3) satisfies
    // MaxSkew(1). In other words, the cluster can still be imbalanced, but scheduler
    // won't make it *more* imbalanced.
    // It's a required field.
    WhenUnsatisfiable UnsatisfiableConstraintAction `json:"whenUnsatisfiable" protobuf:"bytes,3,opt,name=whenUnsatisfiable,casttype=UnsatisfiableConstraintAction"`
    // LabelSelector is used to find matching pods.
    // Pods that match this label selector are counted to determine the number of pods
    // in their corresponding topology domain.
    // +optional
    LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty" protobuf:"bytes,4,opt,name=labelSelector"`
}

PodStatus

// PodStatus represents information about the status of a pod. Status may trail the actual
// state of a system, especially if the node that hosts the pod cannot contact the control
// plane.
type PodStatus struct {
    // The phase of a Pod is a simple, high-level summary of where the Pod is in its lifecycle.
    // The conditions array, the reason and message fields, and the individual container status
    // arrays contain more detail about the pod's status.
    // There are five possible phase values:
    //
    // Pending: The pod has been accepted by the Kubernetes system, but one or more of the
    // container images has not been created. This includes time before being scheduled as
    // well as time spent downloading images over the network, which could take a while.
    // Running: The pod has been bound to a node, and all of the containers have been created.
    // At least one container is still running, or is in the process of starting or restarting.
    // Succeeded: All containers in the pod have terminated in success, and will not be restarted.
    // Failed: All containers in the pod have terminated, and at least one container has
    // terminated in failure. The container either exited with non-zero status or was terminated
    // by the system.
    // Unknown: 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.
    //
    // More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-phase
    // +optional
    Phase PodPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase,casttype=PodPhase"`
    // Current service state of pod.
    // More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-conditions
    // +optional
    // +patchMergeKey=type
    // +patchStrategy=merge
    Conditions []PodCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,2,rep,name=conditions"`
    // A human readable message indicating details about why the pod is in this condition.
    // +optional
    Message string `json:"message,omitempty" protobuf:"bytes,3,opt,name=message"`
    // A brief CamelCase message indicating details about why the pod is in this state.
    // e.g. 'Evicted'
    // +optional
    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"`
}

PodPhase

// PodPhase is a label for the condition of a pod at the current time.
type PodPhase string

// These are the valid statuses of pods.
const (
    // 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.
    // Deprecated: It isn't being set since 2015 (74da3b14b0c0f658b3bb8d2def5094686d0e9095)
    PodUnknown PodPhase = "Unknown"
)

PodCondition

// PodCondition contains details for the current condition of this pod.
type PodCondition struct {
    // Type is the type of the condition.
    // More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-conditions
    Type PodConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=PodConditionType"`
    // Status is the status of the condition.
    // Can be True, False, Unknown.
    // More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-conditions
    Status ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=ConditionStatus"`
    // Last time we probed the condition.
    // +optional
    LastProbeTime metav1.Time `json:"lastProbeTime,omitempty" protobuf:"bytes,3,opt,name=lastProbeTime"`
    // Last time the condition transitioned from one status to another.
    // +optional
    LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"`
    // Unique, one-word, CamelCase reason for the condition's last transition.
    // +optional
    Reason string `json:"reason,omitempty" protobuf:"bytes,5,opt,name=reason"`
    // Human-readable message indicating details about last transition.
    // +optional
    Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
}

PodIP

// IP address information for entries in the (plural) PodIPs field.
// Each entry includes:
//    IP: An IP address allocated to the pod. Routable at least within the cluster.
type PodIP struct {
    // ip is an IP address (IPv4 or IPv6) assigned to the pod
    IP string `json:"ip,omitempty" protobuf:"bytes,1,opt,name=ip"`
}

ContainerStatus

// ContainerStatus contains details for the current status of this container.
type ContainerStatus struct {
    // This must be a DNS_LABEL. Each container in a pod must have a unique name.
    // Cannot be updated.
    Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
    // Details about the container's current condition.
    // +optional
    State ContainerState `json:"state,omitempty" protobuf:"bytes,2,opt,name=state"`
    // Details about the container's last termination condition.
    // +optional
    LastTerminationState ContainerState `json:"lastState,omitempty" protobuf:"bytes,3,opt,name=lastState"`
    // Specifies whether the container has passed its readiness probe.
    Ready bool `json:"ready" protobuf:"varint,4,opt,name=ready"`
    // The number of times the container has been restarted, currently based on
    // the number of dead containers that have not yet been removed.
    // Note that this is calculated from dead containers. But those containers are subject to
    // garbage collection. This value will get capped at 5 by GC.
    RestartCount int32 `json:"restartCount" protobuf:"varint,5,opt,name=restartCount"`
    // The image the container is running.
    // More info: https://kubernetes.io/docs/concepts/containers/images
    // TODO(dchen1107): Which image the container is running with?
    Image string `json:"image" protobuf:"bytes,6,opt,name=image"`
    // ImageID of the container's image.
    ImageID string `json:"imageID" protobuf:"bytes,7,opt,name=imageID"`
    // Container's ID in the format 'docker://<container_id>'.
    // +optional
    ContainerID string `json:"containerID,omitempty" protobuf:"bytes,8,opt,name=containerID"`
    // Specifies whether the container has passed its startup probe.
    // Initialized as false, becomes true after startupProbe is considered successful.
    // Resets to false when the container is restarted, or if kubelet loses state temporarily.
    // Is always true when no startupProbe is defined.
    // +optional
    Started *bool `json:"started,omitempty" protobuf:"varint,9,opt,name=started"`
}

PodQOSClass

// PodQOSClass defines the supported qos classes of Pods.
type PodQOSClass string

const (
    // PodQOSGuaranteed is the Guaranteed qos class.
    PodQOSGuaranteed PodQOSClass = "Guaranteed"
    // PodQOSBurstable is the Burstable qos class.
    PodQOSBurstable PodQOSClass = "Burstable"
    // PodQOSBestEffort is the BestEffort qos class.
    PodQOSBestEffort PodQOSClass = "BestEffort"
)

ConditionStatus

type ConditionStatus string

// These are valid condition statuses. "ConditionTrue" means a resource is in the condition.
// "ConditionFalse" means a resource is not in the condition. "ConditionUnknown" means kubernetes
// can't decide if a resource is in the condition or not. In the future, we could add other
// intermediate conditions, e.g. ConditionDegraded.
const (
    ConditionTrue    ConditionStatus = "True"
    ConditionFalse   ConditionStatus = "False"
    ConditionUnknown ConditionStatus = "Unknown"
)

ContainerState

// ContainerState holds a possible state of container.
// Only one of its members may be specified.
// If none of them is specified, the default one is ContainerStateWaiting.
type ContainerState struct {
    // Details about a waiting container
    // +optional
    Waiting *ContainerStateWaiting `json:"waiting,omitempty" protobuf:"bytes,1,opt,name=waiting"`
    // Details about a running container
    // +optional
    Running *ContainerStateRunning `json:"running,omitempty" protobuf:"bytes,2,opt,name=running"`
    // Details about a terminated container
    // +optional
    Terminated *ContainerStateTerminated `json:"terminated,omitempty" protobuf:"bytes,3,opt,name=terminated"`
}

// ContainerStateWaiting is a waiting state of a container.
type ContainerStateWaiting struct {
    // (brief) reason the container is not yet running.
    // +optional
    Reason string `json:"reason,omitempty" protobuf:"bytes,1,opt,name=reason"`
    // Message regarding why the container is not yet running.
    // +optional
    Message string `json:"message,omitempty" protobuf:"bytes,2,opt,name=message"`
}

// ContainerStateRunning is a running state of a container.
type ContainerStateRunning struct {
    // Time at which the container was last (re-)started
    // +optional
    StartedAt metav1.Time `json:"startedAt,omitempty" protobuf:"bytes,1,opt,name=startedAt"`
}

// ContainerStateTerminated is a terminated state of a container.
type ContainerStateTerminated struct {
    // Exit status from the last termination of the container
    ExitCode int32 `json:"exitCode" protobuf:"varint,1,opt,name=exitCode"`
    // Signal from the last termination of the container
    // +optional
    Signal int32 `json:"signal,omitempty" protobuf:"varint,2,opt,name=signal"`
    // (brief) reason from the last termination of the container
    // +optional
    Reason string `json:"reason,omitempty" protobuf:"bytes,3,opt,name=reason"`
    // Message regarding the last termination of the container
    // +optional
    Message string `json:"message,omitempty" protobuf:"bytes,4,opt,name=message"`
    // Time at which previous execution of the container started
    // +optional
    StartedAt metav1.Time `json:"startedAt,omitempty" protobuf:"bytes,5,opt,name=startedAt"`
    // Time at which the container last terminated
    // +optional
    FinishedAt metav1.Time `json:"finishedAt,omitempty" protobuf:"bytes,6,opt,name=finishedAt"`
    // Container's ID in the format 'docker://<container_id>'
    // +optional
    ContainerID string `json:"containerID,omitempty" protobuf:"bytes,7,opt,name=containerID"`
}

PodTemplateSpec

// PodTemplateSpec describes the data a pod should have when created from a template
type PodTemplateSpec struct {
    // Standard object's metadata.
    // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    // +optional
    metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

    // Specification of the desired behavior of the pod.
    // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
    // +optional
    Spec PodSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
}