Class Volume

  • All Implemented Interfaces:
    IStorage, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable

    @Generated(value="jsii-pacmak/1.69.0 (build f656c31)",
               date="2022-10-09T03:04:24.987Z")
    @Stability(Stable)
    public class Volume
    extends software.constructs.Construct
    implements IStorage
    Volume represents a named volume in a pod that may be accessed by any container in the pod.

    Docker also has a concept of volumes, though it is somewhat looser and less managed. In Docker, a volume is simply a directory on disk or in another Container. Lifetimes are not managed and until very recently there were only local-disk-backed volumes. Docker now provides volume drivers, but the functionality is very limited for now (e.g. as of Docker 1.7 only one volume driver is allowed per Container and there is no way to pass parameters to volumes).

    A Kubernetes volume, on the other hand, has an explicit lifetime - the same as the Pod that encloses it. Consequently, a volume outlives any Containers that run within the Pod, and data is preserved across Container restarts. Of course, when a Pod ceases to exist, the volume will cease to exist, too. Perhaps more importantly than this, Kubernetes supports many types of volumes, and a Pod can use any number of them simultaneously.

    At its core, a volume is just a directory, possibly with some data in it, which is accessible to the Containers in a Pod. How that directory comes to be, the medium that backs it, and the contents of it are determined by the particular volume type used.

    To use a volume, a Pod specifies what volumes to provide for the Pod (the .spec.volumes field) and where to mount those into Containers (the .spec.containers[*].volumeMounts field).

    A process in a container sees a filesystem view composed from their Docker image and volumes. The Docker image is at the root of the filesystem hierarchy, and any volumes are mounted at the specified paths within the image. Volumes can not mount onto other volumes

    • Constructor Detail

      • Volume

        protected Volume​(software.amazon.jsii.JsiiObjectRef objRef)
      • Volume

        protected Volume​(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • Method Detail

      • fromAwsElasticBlockStore

        @Stability(Stable)
        @NotNull
        public static Volume fromAwsElasticBlockStore​(@NotNull
                                                      software.constructs.Construct scope,
                                                      @NotNull
                                                      String id,
                                                      @NotNull
                                                      String volumeId,
                                                      @Nullable
                                                      AwsElasticBlockStoreVolumeOptions options)
        Mounts an Amazon Web Services (AWS) EBS volume into your pod.

        Unlike emptyDir, which is erased when a pod is removed, the contents of an EBS volume are persisted and the volume is unmounted. This means that an EBS volume can be pre-populated with data, and that data can be shared between pods.

        There are some restrictions when using an awsElasticBlockStore volume:

        • the nodes on which pods are running must be AWS EC2 instances.
        • those instances need to be in the same region and availability zone as the EBS volume.
        • EBS only supports a single EC2 instance mounting a volume.

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        volumeId - This parameter is required.
        options -
      • fromAwsElasticBlockStore

        @Stability(Stable)
        @NotNull
        public static Volume fromAwsElasticBlockStore​(@NotNull
                                                      software.constructs.Construct scope,
                                                      @NotNull
                                                      String id,
                                                      @NotNull
                                                      String volumeId)
        Mounts an Amazon Web Services (AWS) EBS volume into your pod.

        Unlike emptyDir, which is erased when a pod is removed, the contents of an EBS volume are persisted and the volume is unmounted. This means that an EBS volume can be pre-populated with data, and that data can be shared between pods.

        There are some restrictions when using an awsElasticBlockStore volume:

        • the nodes on which pods are running must be AWS EC2 instances.
        • those instances need to be in the same region and availability zone as the EBS volume.
        • EBS only supports a single EC2 instance mounting a volume.

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        volumeId - This parameter is required.
      • fromAzureDisk

        @Stability(Stable)
        @NotNull
        public static Volume fromAzureDisk​(@NotNull
                                           software.constructs.Construct scope,
                                           @NotNull
                                           String id,
                                           @NotNull
                                           String diskName,
                                           @NotNull
                                           String diskUri,
                                           @Nullable
                                           AzureDiskVolumeOptions options)
        Mounts a Microsoft Azure Data Disk into a pod.

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        diskName - This parameter is required.
        diskUri - This parameter is required.
        options -
      • fromAzureDisk

        @Stability(Stable)
        @NotNull
        public static Volume fromAzureDisk​(@NotNull
                                           software.constructs.Construct scope,
                                           @NotNull
                                           String id,
                                           @NotNull
                                           String diskName,
                                           @NotNull
                                           String diskUri)
        Mounts a Microsoft Azure Data Disk into a pod.

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        diskName - This parameter is required.
        diskUri - This parameter is required.
      • fromConfigMap

        @Stability(Stable)
        @NotNull
        public static Volume fromConfigMap​(@NotNull
                                           software.constructs.Construct scope,
                                           @NotNull
                                           String id,
                                           @NotNull
                                           IConfigMap configMap,
                                           @Nullable
                                           ConfigMapVolumeOptions options)
        Populate the volume from a ConfigMap.

        The configMap resource provides a way to inject configuration data into Pods. The data stored in a ConfigMap object can be referenced in a volume of type configMap and then consumed by containerized applications running in a Pod.

        When referencing a configMap object, you can simply provide its name in the volume to reference it. You can also customize the path to use for a specific entry in the ConfigMap.

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        configMap - The config map to use to populate the volume. This parameter is required.
        options - Options.
      • fromConfigMap

        @Stability(Stable)
        @NotNull
        public static Volume fromConfigMap​(@NotNull
                                           software.constructs.Construct scope,
                                           @NotNull
                                           String id,
                                           @NotNull
                                           IConfigMap configMap)
        Populate the volume from a ConfigMap.

        The configMap resource provides a way to inject configuration data into Pods. The data stored in a ConfigMap object can be referenced in a volume of type configMap and then consumed by containerized applications running in a Pod.

        When referencing a configMap object, you can simply provide its name in the volume to reference it. You can also customize the path to use for a specific entry in the ConfigMap.

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        configMap - The config map to use to populate the volume. This parameter is required.
      • fromEmptyDir

        @Stability(Stable)
        @NotNull
        public static Volume fromEmptyDir​(@NotNull
                                          software.constructs.Construct scope,
                                          @NotNull
                                          String id,
                                          @NotNull
                                          String name,
                                          @Nullable
                                          EmptyDirVolumeOptions options)
        An emptyDir volume is first created when a Pod is assigned to a Node, and exists as long as that Pod is running on that node.

        As the name says, it is initially empty. Containers in the Pod can all read and write the same files in the emptyDir volume, though that volume can be mounted at the same or different paths in each Container. When a Pod is removed from a node for any reason, the data in the emptyDir is deleted forever.

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        name - This parameter is required.
        options - - Additional options.
        See Also:
        http://kubernetes.io/docs/user-guide/volumes#emptydir
      • fromEmptyDir

        @Stability(Stable)
        @NotNull
        public static Volume fromEmptyDir​(@NotNull
                                          software.constructs.Construct scope,
                                          @NotNull
                                          String id,
                                          @NotNull
                                          String name)
        An emptyDir volume is first created when a Pod is assigned to a Node, and exists as long as that Pod is running on that node.

        As the name says, it is initially empty. Containers in the Pod can all read and write the same files in the emptyDir volume, though that volume can be mounted at the same or different paths in each Container. When a Pod is removed from a node for any reason, the data in the emptyDir is deleted forever.

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        name - This parameter is required.
        See Also:
        http://kubernetes.io/docs/user-guide/volumes#emptydir
      • fromGcePersistentDisk

        @Stability(Stable)
        @NotNull
        public static Volume fromGcePersistentDisk​(@NotNull
                                                   software.constructs.Construct scope,
                                                   @NotNull
                                                   String id,
                                                   @NotNull
                                                   String pdName,
                                                   @Nullable
                                                   GCEPersistentDiskVolumeOptions options)
        Mounts a Google Compute Engine (GCE) persistent disk (PD) into your Pod.

        Unlike emptyDir, which is erased when a pod is removed, the contents of a PD are preserved and the volume is merely unmounted. This means that a PD can be pre-populated with data, and that data can be shared between pods.

        There are some restrictions when using a gcePersistentDisk:

        • the nodes on which Pods are running must be GCE VMs
        • those VMs need to be in the same GCE project and zone as the persistent disk

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        pdName - This parameter is required.
        options -
      • fromGcePersistentDisk

        @Stability(Stable)
        @NotNull
        public static Volume fromGcePersistentDisk​(@NotNull
                                                   software.constructs.Construct scope,
                                                   @NotNull
                                                   String id,
                                                   @NotNull
                                                   String pdName)
        Mounts a Google Compute Engine (GCE) persistent disk (PD) into your Pod.

        Unlike emptyDir, which is erased when a pod is removed, the contents of a PD are preserved and the volume is merely unmounted. This means that a PD can be pre-populated with data, and that data can be shared between pods.

        There are some restrictions when using a gcePersistentDisk:

        • the nodes on which Pods are running must be GCE VMs
        • those VMs need to be in the same GCE project and zone as the persistent disk

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        pdName - This parameter is required.
      • fromHostPath

        @Stability(Stable)
        @NotNull
        public static Volume fromHostPath​(@NotNull
                                          software.constructs.Construct scope,
                                          @NotNull
                                          String id,
                                          @NotNull
                                          String name,
                                          @NotNull
                                          HostPathVolumeOptions options)
        Used to mount a file or directory from the host node's filesystem into a Pod.

        This is not something that most Pods will need, but it offers a powerful escape hatch for some applications.

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        name - This parameter is required.
        options - This parameter is required.
        See Also:
        https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
      • fromPersistentVolumeClaim

        @Stability(Stable)
        @NotNull
        public static Volume fromPersistentVolumeClaim​(@NotNull
                                                       software.constructs.Construct scope,
                                                       @NotNull
                                                       String id,
                                                       @NotNull
                                                       IPersistentVolumeClaim claim,
                                                       @Nullable
                                                       PersistentVolumeClaimVolumeOptions options)
        Used to mount a PersistentVolume into a Pod.

        PersistentVolumeClaims are a way for users to "claim" durable storage (such as a GCE PersistentDisk or an iSCSI volume) without knowing the details of the particular cloud environment.

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        claim - This parameter is required.
        options -
        See Also:
        https://kubernetes.io/docs/concepts/storage/persistent-volumes/
      • fromPersistentVolumeClaim

        @Stability(Stable)
        @NotNull
        public static Volume fromPersistentVolumeClaim​(@NotNull
                                                       software.constructs.Construct scope,
                                                       @NotNull
                                                       String id,
                                                       @NotNull
                                                       IPersistentVolumeClaim claim)
        Used to mount a PersistentVolume into a Pod.

        PersistentVolumeClaims are a way for users to "claim" durable storage (such as a GCE PersistentDisk or an iSCSI volume) without knowing the details of the particular cloud environment.

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        claim - This parameter is required.
        See Also:
        https://kubernetes.io/docs/concepts/storage/persistent-volumes/
      • fromSecret

        @Stability(Stable)
        @NotNull
        public static Volume fromSecret​(@NotNull
                                        software.constructs.Construct scope,
                                        @NotNull
                                        String id,
                                        @NotNull
                                        ISecret secr,
                                        @Nullable
                                        SecretVolumeOptions options)
        Populate the volume from a Secret.

        A secret volume is used to pass sensitive information, such as passwords, to Pods. You can store secrets in the Kubernetes API and mount them as files for use by pods without coupling to Kubernetes directly.

        secret volumes are backed by tmpfs (a RAM-backed filesystem) so they are never written to non-volatile storage.

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        secr - The secret to use to populate the volume. This parameter is required.
        options - Options.
        See Also:
        https://kubernetes.io/docs/concepts/storage/volumes/#secret
      • fromSecret

        @Stability(Stable)
        @NotNull
        public static Volume fromSecret​(@NotNull
                                        software.constructs.Construct scope,
                                        @NotNull
                                        String id,
                                        @NotNull
                                        ISecret secr)
        Populate the volume from a Secret.

        A secret volume is used to pass sensitive information, such as passwords, to Pods. You can store secrets in the Kubernetes API and mount them as files for use by pods without coupling to Kubernetes directly.

        secret volumes are backed by tmpfs (a RAM-backed filesystem) so they are never written to non-volatile storage.

        Parameters:
        scope - This parameter is required.
        id - This parameter is required.
        secr - The secret to use to populate the volume. This parameter is required.
        See Also:
        https://kubernetes.io/docs/concepts/storage/volumes/#secret
      • asVolume

        @Stability(Stable)
        @NotNull
        public Volume asVolume()
        Convert the piece of storage into a concrete volume.
        Specified by:
        asVolume in interface IStorage
      • getName

        @Stability(Stable)
        @NotNull
        public String getName()