Pod Volume

简要概述

TODO;

关键站点:

  1. https://kubernetes-csi.github.io/docs/

数据结构

Volume

// Volume represents a named volume in a pod that may be accessed by any container in the pod.
type Volume struct {
    // Volume's name.
    // Must be a DNS_LABEL and unique within the pod.
    // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
    Name string `json:"name" protobuf:"bytes,1,opt,name=name"`
    // VolumeSource represents the location and type of the mounted volume.
    // If not specified, the Volume is implied to be an EmptyDir.
    // This implied behavior is deprecated and will be removed in a future version.
    VolumeSource `json:",inline" protobuf:"bytes,2,opt,name=volumeSource"`
}

VolumeSource

// Represents the source of a volume to mount.
// Only one of its members may be specified.
type VolumeSource struct {
    // HostPath represents a pre-existing file or directory on the host
    // machine that is directly exposed to the container. This is generally
    // used for system agents or other privileged things that are allowed
    // to see the host machine. Most containers will NOT need this.
    // More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath
    // ---
    // TODO(jonesdl) We need to restrict who can use host directory mounts and who can/can not
    // mount host directories as read/write.
    // +optional
    HostPath *HostPathVolumeSource `json:"hostPath,omitempty" protobuf:"bytes,1,opt,name=hostPath"`

    // EmptyDir represents a temporary directory that shares a pod's lifetime.
    // More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir
    // +optional
    EmptyDir *EmptyDirVolumeSource `json:"emptyDir,omitempty" protobuf:"bytes,2,opt,name=emptyDir"`

    // Secret represents a secret that should populate this volume.
    // More info: https://kubernetes.io/docs/concepts/storage/volumes#secret
    // +optional
    Secret *SecretVolumeSource `json:"secret,omitempty" protobuf:"bytes,6,opt,name=secret"`

    // NFS represents an NFS mount on the host that shares a pod's lifetime
    // More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs
    // +optional
    NFS *NFSVolumeSource `json:"nfs,omitempty" protobuf:"bytes,7,opt,name=nfs"`

    // ISCSI represents an ISCSI Disk resource that is attached to a
    // kubelet's host machine and then exposed to the pod.
    // More info: https://examples.k8s.io/volumes/iscsi/README.md
    // +optional
    ISCSI *ISCSIVolumeSource `json:"iscsi,omitempty" protobuf:"bytes,8,opt,name=iscsi"`

    // PersistentVolumeClaimVolumeSource represents a reference to a
    // PersistentVolumeClaim in the same namespace.
    // More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
    // +optional
    PersistentVolumeClaim *PersistentVolumeClaimVolumeSource `json:"persistentVolumeClaim,omitempty" protobuf:"bytes,10,opt,name=persistentVolumeClaim"`

    // DownwardAPI represents downward API about the pod that should populate this volume
    // +optional
    DownwardAPI *DownwardAPIVolumeSource `json:"downwardAPI,omitempty" protobuf:"bytes,16,opt,name=downwardAPI"`

    // FC represents a Fibre Channel resource that is attached to a kubelet's host machine and then exposed to the pod.
    // +optional
    FC *FCVolumeSource `json:"fc,omitempty" protobuf:"bytes,17,opt,name=fc"`

    // ConfigMap represents a configMap that should populate this volume
    // +optional
    ConfigMap *ConfigMapVolumeSource `json:"configMap,omitempty" protobuf:"bytes,19,opt,name=configMap"`

    // Items for all in one resources secrets, configmaps, and downward API
    Projected *ProjectedVolumeSource `json:"projected,omitempty" protobuf:"bytes,26,opt,name=projected"`

    // Local represents directly-attached storage with node affinity
    // +optional
    Local *LocalVolumeSource `json:"local,omitempty" protobuf:"bytes,20,opt,name=local"`

    // CSI (Container Storage Interface) represents ephemeral storage that is handled by certain external CSI drivers (Beta feature).
    // +optional
    CSI *CSIVolumeSource `json:"csi,omitempty" protobuf:"bytes,28,opt,name=csi"`

    // Ephemeral represents a volume that is handled by a cluster storage driver.
    // The volume's lifecycle is tied to the pod that defines it - it will be created before the pod starts,
    // and deleted when the pod is removed.
    //
    // Use this if:
    // a) the volume is only needed while the pod runs,
    // b) features of normal volumes like restoring from snapshot or capacity
    //    tracking are needed,
    // c) the storage driver is specified through a storage class, and
    // d) the storage driver supports dynamic volume provisioning through
    //    a PersistentVolumeClaim (see EphemeralVolumeSource for more
    //    information on the connection between this volume type
    //    and PersistentVolumeClaim).
    //
    // Use PersistentVolumeClaim or one of the vendor-specific
    // APIs for volumes that persist for longer than the lifecycle
    // of an individual pod.
    //
    // Use CSI for light-weight local ephemeral volumes if the CSI driver is meant to
    // be used that way - see the documentation of the driver for
    // more information.
    //
    // A pod can use both types of ephemeral volumes and
    // persistent volumes at the same time.
    //
    // This is a beta feature and only available when the GenericEphemeralVolume
    // feature gate is enabled.
    //
    // +optional
    Ephemeral *EphemeralVolumeSource `json:"ephemeral,omitempty" protobuf:"bytes,29,opt,name=ephemeral"`

	// 以下类型建议使用对应的 csi 插件实现
    GCEPersistentDisk *GCEPersistentDiskVolumeSource `json:"gcePersistentDisk,omitempty" protobuf:"bytes,3,opt,name=gcePersistentDisk"`
    AWSElasticBlockStore *AWSElasticBlockStoreVolumeSource `json:"awsElasticBlockStore,omitempty" protobuf:"bytes,4,opt,name=awsElasticBlockStore"`
    GitRepo *GitRepoVolumeSource `json:"gitRepo,omitempty" protobuf:"bytes,5,opt,name=gitRepo"`
    Glusterfs *GlusterfsVolumeSource `json:"glusterfs,omitempty" protobuf:"bytes,9,opt,name=glusterfs"`
    RBD *RBDVolumeSource `json:"rbd,omitempty" protobuf:"bytes,11,opt,name=rbd"`
    Cinder *CinderVolumeSource `json:"cinder,omitempty" protobuf:"bytes,13,opt,name=cinder"`
    CephFS *CephFSVolumeSource `json:"cephfs,omitempty" protobuf:"bytes,14,opt,name=cephfs"`
    AzureFile *AzureFileVolumeSource `json:"azureFile,omitempty" protobuf:"bytes,18,opt,name=azureFile"`
    VsphereVolume *VsphereVirtualDiskVolumeSource `json:"vsphereVolume,omitempty" protobuf:"bytes,20,opt,name=vsphereVolume"`
    AzureDisk *AzureDiskVolumeSource `json:"azureDisk,omitempty" protobuf:"bytes,22,opt,name=azureDisk"`
    PortworxVolume *PortworxVolumeSource `json:"portworxVolume,omitempty" protobuf:"bytes,24,opt,name=portworxVolume"`
    Quobyte *QuobyteVolumeSource `json:"quobyte,omitempty" protobuf:"bytes,21,opt,name=quobyte"`
    ScaleIO *ScaleIOVolumeSource `json:"scaleIO,omitempty" protobuf:"bytes,25,opt,name=scaleIO"`
    StorageOS *StorageOSVolumeSource `json:"storageos,omitempty" protobuf:"bytes,27,opt,name=storageos"`
    PhotonPersistentDisk *PhotonPersistentDiskVolumeSource `json:"photonPersistentDisk,omitempty" protobuf:"bytes,23,opt,name=photonPersistentDisk"`

	// 旧版外部存储插件,建议使用 csi 插件实现
    FlexVolume *FlexVolumeSource `json:"flexVolume,omitempty" protobuf:"bytes,12,opt,name=flexVolume"`

	// 已终止的开源项目
	// https://github.com/ClusterHQ/flocker/issues/3017
    Flocker *FlockerVolumeSource `json:"flocker,omitempty" protobuf:"bytes,15,opt,name=flocker"`
}

常见存储卷

HostPathVolumeSource

// Represents a host path mapped into a pod.
// Host path volumes do not support ownership management or SELinux relabeling.
type HostPathVolumeSource struct {
    // Path of the directory on the host.
    // If the path is a symlink, it will follow the link to the real path.
    // More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath
    Path string `json:"path" protobuf:"bytes,1,opt,name=path"`
    // Type for HostPath Volume
    // Defaults to ""
    // More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath
    // +optional
    Type *HostPathType `json:"type,omitempty" protobuf:"bytes,2,opt,name=type"`
}

EmptyDirVolumeSource

// Represents an empty directory for a pod.
// Empty directory volumes support ownership management and SELinux relabeling.
type EmptyDirVolumeSource struct {
    // What type of storage medium should back this directory.
    // The default is "" which means to use the node's default medium.
    // Must be an empty string (default) or Memory.
    // More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir
    // +optional
    Medium StorageMedium `json:"medium,omitempty" protobuf:"bytes,1,opt,name=medium,casttype=StorageMedium"`
    // Total amount of local storage required for this EmptyDir volume.
    // The size limit is also applicable for memory medium.
    // The maximum usage on memory medium EmptyDir would be the minimum value between
    // the SizeLimit specified here and the sum of memory limits of all containers in a pod.
    // The default is nil which means that the limit is undefined.
    // More info: http://kubernetes.io/docs/user-guide/volumes#emptydir
    // +optional
    SizeLimit *resource.Quantity `json:"sizeLimit,omitempty" protobuf:"bytes,2,opt,name=sizeLimit"`
}

SecretVolumeSource

// Adapts a Secret into a volume.
//
// The contents of the target Secret's Data field will be presented in a volume
// as files using the keys in the Data field as the file names.
// Secret volumes support ownership management and SELinux relabeling.
type SecretVolumeSource struct {
    // Name of the secret in the pod's namespace to use.
    // More info: https://kubernetes.io/docs/concepts/storage/volumes#secret
    // +optional
    SecretName string `json:"secretName,omitempty" protobuf:"bytes,1,opt,name=secretName"`
    // If unspecified, each key-value pair in the Data field of the referenced
    // Secret will be projected into the volume as a file whose name is the
    // key and content is the value. If specified, the listed keys will be
    // projected into the specified paths, and unlisted keys will not be
    // present. If a key is specified which is not present in the Secret,
    // the volume setup will error unless it is marked optional. Paths must be
    // relative and may not contain the '..' path or start with '..'.
    // +optional
    Items []KeyToPath `json:"items,omitempty" protobuf:"bytes,2,rep,name=items"`
    // Optional: mode bits used to set permissions on created files by default.
    // Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511.
    // YAML accepts both octal and decimal values, JSON requires decimal values
    // for mode bits. Defaults to 0644.
    // Directories within the path are not affected by this setting.
    // This might be in conflict with other options that affect the file
    // mode, like fsGroup, and the result can be other mode bits set.
    // +optional
    DefaultMode *int32 `json:"defaultMode,omitempty" protobuf:"bytes,3,opt,name=defaultMode"`
    // Specify whether the Secret or its keys must be defined
    // +optional
    Optional *bool `json:"optional,omitempty" protobuf:"varint,4,opt,name=optional"`
}

NFSVolumeSource

// Represents an NFS mount that lasts the lifetime of a pod.
// NFS volumes do not support ownership management or SELinux relabeling.
type NFSVolumeSource struct {
    // Server is the hostname or IP address of the NFS server.
    // More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs
    Server string `json:"server" protobuf:"bytes,1,opt,name=server"`

    // Path that is exported by the NFS server.
    // More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs
    Path string `json:"path" protobuf:"bytes,2,opt,name=path"`

    // ReadOnly here will force
    // the NFS export to be mounted with read-only permissions.
    // Defaults to false.
    // More info: https://kubernetes.io/docs/concepts/storage/volumes#nfs
    // +optional
    ReadOnly bool `json:"readOnly,omitempty" protobuf:"varint,3,opt,name=readOnly"`
}

ISCSIVolumeSource

// Represents an ISCSI disk.
// ISCSI volumes can only be mounted as read/write once.
// ISCSI volumes support ownership management and SELinux relabeling.
type ISCSIVolumeSource struct {
    // iSCSI Target Portal. The Portal is either an IP or ip_addr:port if the port
    // is other than default (typically TCP ports 860 and 3260).
    TargetPortal string `json:"targetPortal" protobuf:"bytes,1,opt,name=targetPortal"`
    // Target iSCSI Qualified Name.
    IQN string `json:"iqn" protobuf:"bytes,2,opt,name=iqn"`
    // iSCSI Target Lun number.
    Lun int32 `json:"lun" protobuf:"varint,3,opt,name=lun"`
    // iSCSI Interface Name that uses an iSCSI transport.
    // Defaults to 'default' (tcp).
    // +optional
    ISCSIInterface string `json:"iscsiInterface,omitempty" protobuf:"bytes,4,opt,name=iscsiInterface"`
    // Filesystem type of the volume that you want to mount.
    // Tip: Ensure that the filesystem type is supported by the host operating system.
    // Examples: "ext4", "xfs", "ntfs". Implicitly inferred to be "ext4" if unspecified.
    // More info: https://kubernetes.io/docs/concepts/storage/volumes#iscsi
    // TODO: how do we prevent errors in the filesystem from compromising the machine
    // +optional
    FSType string `json:"fsType,omitempty" protobuf:"bytes,5,opt,name=fsType"`
    // ReadOnly here will force the ReadOnly setting in VolumeMounts.
    // Defaults to false.
    // +optional
    ReadOnly bool `json:"readOnly,omitempty" protobuf:"varint,6,opt,name=readOnly"`
    // iSCSI Target Portal List. The portal is either an IP or ip_addr:port if the port
    // is other than default (typically TCP ports 860 and 3260).
    // +optional
    Portals []string `json:"portals,omitempty" protobuf:"bytes,7,opt,name=portals"`
    // whether support iSCSI Discovery CHAP authentication
    // +optional
    DiscoveryCHAPAuth bool `json:"chapAuthDiscovery,omitempty" protobuf:"varint,8,opt,name=chapAuthDiscovery"`
    // whether support iSCSI Session CHAP authentication
    // +optional
    SessionCHAPAuth bool `json:"chapAuthSession,omitempty" protobuf:"varint,11,opt,name=chapAuthSession"`
    // CHAP Secret for iSCSI target and initiator authentication
    // +optional
    SecretRef *LocalObjectReference `json:"secretRef,omitempty" protobuf:"bytes,10,opt,name=secretRef"`
    // Custom iSCSI Initiator Name.
    // If initiatorName is specified with iscsiInterface simultaneously, new iSCSI interface
    // <target portal>:<volume name> will be created for the connection.
    // +optional
    InitiatorName *string `json:"initiatorName,omitempty" protobuf:"bytes,12,opt,name=initiatorName"`
}

PersistentVolumeClaimVolumeSource

// PersistentVolumeClaimVolumeSource references the user's PVC in the same namespace.
// This volume finds the bound PV and mounts that volume for the pod. A
// PersistentVolumeClaimVolumeSource is, essentially, a wrapper around another
// type of volume that is owned by someone else (the system).
type PersistentVolumeClaimVolumeSource struct {
    // ClaimName is the name of a PersistentVolumeClaim in the same namespace as the pod using this volume.
    // More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
    ClaimName string `json:"claimName" protobuf:"bytes,1,opt,name=claimName"`
    // Will force the ReadOnly setting in VolumeMounts.
    // Default false.
    // +optional
    ReadOnly bool `json:"readOnly,omitempty" protobuf:"varint,2,opt,name=readOnly"`
}

DownwardAPIVolumeSource

// DownwardAPIVolumeSource represents a volume containing downward API info.
// Downward API volumes support ownership management and SELinux relabeling.
type DownwardAPIVolumeSource struct {
    // Items is a list of downward API volume file
    // +optional
    Items []DownwardAPIVolumeFile `json:"items,omitempty" protobuf:"bytes,1,rep,name=items"`
    // Optional: mode bits to use on created files by default. Must be a
    // Optional: mode bits used to set permissions on created files by default.
    // Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511.
    // YAML accepts both octal and decimal values, JSON requires decimal values for mode bits.
    // Defaults to 0644.
    // Directories within the path are not affected by this setting.
    // This might be in conflict with other options that affect the file
    // mode, like fsGroup, and the result can be other mode bits set.
    // +optional
    DefaultMode *int32 `json:"defaultMode,omitempty" protobuf:"varint,2,opt,name=defaultMode"`
}

FCVolumeSource

// Represents a Fibre Channel volume.
// Fibre Channel volumes can only be mounted as read/write once.
// Fibre Channel volumes support ownership management and SELinux relabeling.
type FCVolumeSource struct {
    // Optional: FC target worldwide names (WWNs)
    // +optional
    TargetWWNs []string `json:"targetWWNs,omitempty" protobuf:"bytes,1,rep,name=targetWWNs"`
    // Optional: FC target lun number
    // +optional
    Lun *int32 `json:"lun,omitempty" protobuf:"varint,2,opt,name=lun"`
    // Filesystem type to mount.
    // Must be a filesystem type supported by the host operating system.
    // Ex. "ext4", "xfs", "ntfs". Implicitly inferred to be "ext4" if unspecified.
    // TODO: how do we prevent errors in the filesystem from compromising the machine
    // +optional
    FSType string `json:"fsType,omitempty" protobuf:"bytes,3,opt,name=fsType"`
    // Optional: Defaults to false (read/write). ReadOnly here will force
    // the ReadOnly setting in VolumeMounts.
    // +optional
    ReadOnly bool `json:"readOnly,omitempty" protobuf:"varint,4,opt,name=readOnly"`
    // Optional: FC volume world wide identifiers (wwids)
    // Either wwids or combination of targetWWNs and lun must be set, but not both simultaneously.
    // +optional
    WWIDs []string `json:"wwids,omitempty" protobuf:"bytes,5,rep,name=wwids"`
}

ConfigMapVolumeSource

// Adapts a ConfigMap into a volume.
//
// The contents of the target ConfigMap's Data field will be presented in a
// volume as files using the keys in the Data field as the file names, unless
// the items element is populated with specific mappings of keys to paths.
// ConfigMap volumes support ownership management and SELinux relabeling.
type ConfigMapVolumeSource struct {
    LocalObjectReference `json:",inline" protobuf:"bytes,1,opt,name=localObjectReference"`
    // If unspecified, each key-value pair in the Data field of the referenced
    // ConfigMap will be projected into the volume as a file whose name is the
    // key and content is the value. If specified, the listed keys will be
    // projected into the specified paths, and unlisted keys will not be
    // present. If a key is specified which is not present in the ConfigMap,
    // the volume setup will error unless it is marked optional. Paths must be
    // relative and may not contain the '..' path or start with '..'.
    // +optional
    Items []KeyToPath `json:"items,omitempty" protobuf:"bytes,2,rep,name=items"`
    // Optional: mode bits used to set permissions on created files by default.
    // Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511.
    // YAML accepts both octal and decimal values, JSON requires decimal values for mode bits.
    // Defaults to 0644.
    // Directories within the path are not affected by this setting.
    // This might be in conflict with other options that affect the file
    // mode, like fsGroup, and the result can be other mode bits set.
    // +optional
    DefaultMode *int32 `json:"defaultMode,omitempty" protobuf:"varint,3,opt,name=defaultMode"`
    // Specify whether the ConfigMap or its keys must be defined
    // +optional
    Optional *bool `json:"optional,omitempty" protobuf:"varint,4,opt,name=optional"`
}

ProjectedVolumeSource

// Represents a projected volume source
type ProjectedVolumeSource struct {
    // list of volume projections
    // +optional
    Sources []VolumeProjection `json:"sources" protobuf:"bytes,1,rep,name=sources"`
    // Mode bits used to set permissions on created files by default.
    // Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511.
    // YAML accepts both octal and decimal values, JSON requires decimal values for mode bits.
    // Directories within the path are not affected by this setting.
    // This might be in conflict with other options that affect the file
    // mode, like fsGroup, and the result can be other mode bits set.
    // +optional
    DefaultMode *int32 `json:"defaultMode,omitempty" protobuf:"varint,2,opt,name=defaultMode"`
}

LocalVolumeSource

// Local represents directly-attached storage with node affinity (Beta feature)
type LocalVolumeSource struct {
    // The full path to the volume on the node.
    // It can be either a directory or block device (disk, partition, ...).
    Path string `json:"path" protobuf:"bytes,1,opt,name=path"`

    // Filesystem type to mount.
    // It applies only when the Path is a block device.
    // Must be a filesystem type supported by the host operating system.
    // Ex. "ext4", "xfs", "ntfs". The default value is to auto-select a fileystem if unspecified.
    // +optional
    FSType *string `json:"fsType,omitempty" protobuf:"bytes,2,opt,name=fsType"`
}

CSIVolumeSource

// Represents a source location of a volume to mount, managed by an external CSI driver
type CSIVolumeSource struct {
    // Driver is the name of the CSI driver that handles this volume.
    // Consult with your admin for the correct name as registered in the cluster.
    Driver string `json:"driver" protobuf:"bytes,1,opt,name=driver"`

    // Specifies a read-only configuration for the volume.
    // Defaults to false (read/write).
    // +optional
    ReadOnly *bool `json:"readOnly,omitempty" protobuf:"varint,2,opt,name=readOnly"`

    // Filesystem type to mount. Ex. "ext4", "xfs", "ntfs".
    // If not provided, the empty value is passed to the associated CSI driver
    // which will determine the default filesystem to apply.
    // +optional
    FSType *string `json:"fsType,omitempty" protobuf:"bytes,3,opt,name=fsType"`

    // VolumeAttributes stores driver-specific properties that are passed to the CSI
    // driver. Consult your driver's documentation for supported values.
    // +optional
    VolumeAttributes map[string]string `json:"volumeAttributes,omitempty" protobuf:"bytes,4,rep,name=volumeAttributes"`

    // NodePublishSecretRef is a reference to the secret object containing
    // sensitive information to pass to the CSI driver to complete the CSI
    // NodePublishVolume and NodeUnpublishVolume calls.
    // This field is optional, and  may be empty if no secret is required. If the
    // secret object contains more than one secret, all secret references are passed.
    // +optional
    NodePublishSecretRef *LocalObjectReference `json:"nodePublishSecretRef,omitempty" protobuf:"bytes,5,opt,name=nodePublishSecretRef"`
}

EphemeralVolumeSource

// Represents an ephemeral volume that is handled by a normal storage driver.
type EphemeralVolumeSource struct {
    // Will be used to create a stand-alone PVC to provision the volume.
    // The pod in which this EphemeralVolumeSource is embedded will be the
    // owner of the PVC, i.e. the PVC will be deleted together with the
    // pod.  The name of the PVC will be `<pod name>-<volume name>` where
    // `<volume name>` is the name from the `PodSpec.Volumes` array
    // entry. Pod validation will reject the pod if the concatenated name
    // is not valid for a PVC (for example, too long).
    //
    // An existing PVC with that name that is not owned by the pod
    // will *not* be used for the pod to avoid using an unrelated
    // volume by mistake. Starting the pod is then blocked until
    // the unrelated PVC is removed. If such a pre-created PVC is
    // meant to be used by the pod, the PVC has to updated with an
    // owner reference to the pod once the pod exists. Normally
    // this should not be necessary, but it may be useful when
    // manually reconstructing a broken cluster.
    //
    // This field is read-only and no changes will be made by Kubernetes
    // to the PVC after it has been created.
    //
    // Required, must not be nil.
    VolumeClaimTemplate *PersistentVolumeClaimTemplate `json:"volumeClaimTemplate,omitempty" protobuf:"bytes,1,opt,name=volumeClaimTemplate"`

    // ReadOnly is tombstoned to show why 2 is a reserved protobuf tag.
    // ReadOnly bool `json:"readOnly,omitempty" protobuf:"varint,2,opt,name=readOnly"`
}

存储卷属性

HostPathType

type HostPathType string

const (
    // For backwards compatible, leave it empty if unset
    HostPathUnset HostPathType = ""
    // If nothing exists at the given path, an empty directory will be created there
    // as needed with file mode 0755, having the same group and ownership with Kubelet.
    HostPathDirectoryOrCreate HostPathType = "DirectoryOrCreate"
    // A directory must exist at the given path
    HostPathDirectory HostPathType = "Directory"
    // If nothing exists at the given path, an empty file will be created there
    // as needed with file mode 0644, having the same group and ownership with Kubelet.
    HostPathFileOrCreate HostPathType = "FileOrCreate"
    // A file must exist at the given path
    HostPathFile HostPathType = "File"
    // A UNIX socket must exist at the given path
    HostPathSocket HostPathType = "Socket"
    // A character device must exist at the given path
    HostPathCharDev HostPathType = "CharDevice"
    // A block device must exist at the given path
    HostPathBlockDev HostPathType = "BlockDevice"
)

StorageMedium

// StorageMedium defines ways that storage can be allocated to a volume.
type StorageMedium string

const (
    StorageMediumDefault         StorageMedium = ""           // use whatever the default is for the node, assume anything we don't explicitly handle is this
    StorageMediumMemory          StorageMedium = "Memory"     // use memory (e.g. tmpfs on linux)
    StorageMediumHugePages       StorageMedium = "HugePages"  // use hugepages
    StorageMediumHugePagesPrefix StorageMedium = "HugePages-" // prefix for full medium notation HugePages-<size>
)

resource.Quantity

TODO;

PersistentVolumeClaimTemplate

// PersistentVolumeClaimTemplate is used to produce
// PersistentVolumeClaim objects as part of an EphemeralVolumeSource.
type PersistentVolumeClaimTemplate struct {
    // May contain labels and annotations that will be copied into the PVC
    // when creating it. No other fields are allowed and will be rejected during
    // validation.
    //
    // +optional
    metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

    // The specification for the PersistentVolumeClaim. The entire content is
    // copied unchanged into the PVC that gets created from this
    // template. The same fields as in a PersistentVolumeClaim
    // are also valid here.
    Spec PersistentVolumeClaimSpec `json:"spec" protobuf:"bytes,2,name=spec"`
}

PersistentVolumeClaimSpec

// PersistentVolumeClaimSpec describes the common attributes of storage devices
// and allows a Source for provider-specific attributes
type PersistentVolumeClaimSpec struct {
    // AccessModes contains the desired access modes the volume should have.
    // More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes-1
    // +optional
    AccessModes []PersistentVolumeAccessMode `json:"accessModes,omitempty" protobuf:"bytes,1,rep,name=accessModes,casttype=PersistentVolumeAccessMode"`
    // A label query over volumes to consider for binding.
    // +optional
    Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,4,opt,name=selector"`
    // Resources represents the minimum resources the volume should have.
    // More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#resources
    // +optional
    Resources ResourceRequirements `json:"resources,omitempty" protobuf:"bytes,2,opt,name=resources"`
    // VolumeName is the binding reference to the PersistentVolume backing this claim.
    // +optional
    VolumeName string `json:"volumeName,omitempty" protobuf:"bytes,3,opt,name=volumeName"`
    // Name of the StorageClass required by the claim.
    // More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1
    // +optional
    StorageClassName *string `json:"storageClassName,omitempty" protobuf:"bytes,5,opt,name=storageClassName"`
    // volumeMode defines what type of volume is required by the claim.
    // Value of Filesystem is implied when not included in claim spec.
    // +optional
    VolumeMode *PersistentVolumeMode `json:"volumeMode,omitempty" protobuf:"bytes,6,opt,name=volumeMode,casttype=PersistentVolumeMode"`
    // This field can be used to specify either:
    // * An existing VolumeSnapshot object (snapshot.storage.k8s.io/VolumeSnapshot)
    // * An existing PVC (PersistentVolumeClaim)
    // If the provisioner or an external controller can support the specified data source,
    // it will create a new volume based on the contents of the specified data source.
    // If the AnyVolumeDataSource feature gate is enabled, this field will always have
    // the same contents as the DataSourceRef field.
    // +optional
    DataSource *TypedLocalObjectReference `json:"dataSource,omitempty" protobuf:"bytes,7,opt,name=dataSource"`
    // Specifies the object from which to populate the volume with data, if a non-empty
    // volume is desired. This may be any local object from a non-empty API group (non
    // core object) or a PersistentVolumeClaim object.
    // When this field is specified, volume binding will only succeed if the type of
    // the specified object matches some installed volume populator or dynamic
    // provisioner.
    // This field will replace the functionality of the DataSource field and as such
    // if both fields are non-empty, they must have the same value. For backwards
    // compatibility, both fields (DataSource and DataSourceRef) will be set to the same
    // value automatically if one of them is empty and the other is non-empty.
    // There are two important differences between DataSource and DataSourceRef:
    // * While DataSource only allows two specific types of objects, DataSourceRef
    //   allows any non-core object, as well as PersistentVolumeClaim objects.
    // * While DataSource ignores disallowed values (dropping them), DataSourceRef
    //   preserves all values, and generates an error if a disallowed value is
    //   specified.
    // (Alpha) Using this field requires the AnyVolumeDataSource feature gate to be enabled.
    // +optional
    DataSourceRef *TypedLocalObjectReference `json:"dataSourceRef,omitempty" protobuf:"bytes,8,opt,name=dataSourceRef"`
}



最后修改 2023.09.24: refactor: update pod volume (9167cf7)