AWS EBS CSI Driver

repository·master·Indexed 22 days ago

https://github.com/kubernetes-sigs/aws-ebs-csi-driver

The Amazon EBS CSI Driver allows Kubernetes clusters to manage the lifecycle of Amazon EBS volumes and snapshots, supporting both static and dynamic provisioning. It enables features such as volume cloning (v1.51.0+), raw block device consumption, generic ephemeral volumes (Kubernetes 1.23+), node-local volumes, and volume modification via VolumeAttributesClass.

Tokens
40.2K
Snippets
72
Records
128
Agent score
77%

What's inside aws-ebs-csi-driver

  1. Overview of Amazon EBS CSI Driver features

    master

    The Amazon Elastic Block Store (EBS) CSI Driver provides a Container Storage Interface (CSI) to manage the lifecycle of Amazon EBS volumes and snapshots within Kubernetes.

    Key capabilities include:

    • Static Provisioning: Manually associating existing EBS volumes with a Kubernetes PersistentVolume (PV).
    • Dynamic Provisioning: Automatically creating EBS volumes and PersistentVolumes (PV) from PersistentVolumeClaims (PVC) using a StorageClass for configuration.
    • Mount Options: Defining how volumes are mounted via the PersistentVolume (PV) resource.
    • Block Volumes: Using EBS volumes as raw block devices.
    • Volume Snapshots: Managing Kubernetes snapshots to create or restore EBS volumes.
    • Volume Resizing: Expanding volume capacity by updating the PersistentVolumeClaim (PVC) size.
    • Volume Modification: Changing volume properties like type, IOPS, or throughput using a VolumeAttributesClass.
    • Node-Local Volumes: Using a single cluster-wide PV/PVC to mount pre-attached, node-specific EBS volumes for local caching.
  2. How Multi-Attach works with EBS volumes

    master

    Multi-attach allows a single EBS volume to be attached to multiple EC2 instances within the same Availability Zone (AZ). This enables several pods running on different nodes to share the same volume.

    To enable multi-attach, you must set PersistentVolumeClaim.spec.accessMode to ReadWriteMany.

    Critical Requirements & Limitations:

    • Volume Type: Currently, the EBS CSI driver only supports multi-attach for io2 volumes.
    • Volume Mode: Must be used in Block mode.
    • Safety: You must implement application-level coordination (such as I/O fencing) to prevent data loss and silent data corruption. The driver does not manage file-system level concurrency for you.
  3. How volume expansion and modification are coalesced

    master

    To avoid hitting AWS EC2 ModifyVolume API cooldowns, the driver implements request coalescing.

    When a user updates a PersistentVolumeClaim (PVC) with a new size (triggering ControllerExpandVolume) and a new VolumeAttributesClassName (triggering ControllerModifyVolume) simultaneously, the driver waits up to two seconds to merge these into a single EC2 ModifyVolume call.

    The workflow is as follows:

    1. The csi-resizer sends both RPCs to the ebs-plugin.
    2. The plugin merges the requests and calls EC2 CreateTags (if needed) and EC2 ModifyVolume.
    3. The plugin polls EC2 DescribeVolumeModifications until the state is optimizing or completed.
    4. If the volume is a Block Device, the expansion is considered successful.
    5. If the volume is a Filesystem, the driver marks the PVC as FSResizeRequired, triggering the Kubelet to call NodeExpandVolume for an online filesystem resize.
  4. How Volume Snapshots work in the EBS CSI Driver

    master
    The EBS CSI driver implements volume snapshotting functionality by leveraging the external snapshotter sidecar. It allows users to create and manage snapshots of EBS volumes using the VolumeSnapshot Kubernetes custom resource. This mechanism enables the restoration of data from existing EBS snapshots into new PersistentVolumes.
  5. Considerations for EBS Volume Modification

    master

    When performing volume modifications, keep the following in mind:

    • AWS Cooldown Periods: Modifications are subject to AWS EBS volume modification limitations. If a modification is initiated during a cooldown period, it will not progress until the cooldown expires.
    • Validation: The EBS CSI Driver performs minimal client-side validation. Ensure that the desired volume properties (type, IOPS, throughput) are permissible for the specific volume type in AWS.
  6. Configure driver tolerations and node startup taints

    master

    Driver Tolerations

    By default, the controller tolerates the CriticalAddonsOnly taint. The driver node tolerates all taints. To restrict the driver node from running on all nodes, set Value.node.tolerateAllTaints to false and define custom policies in Value.node.tolerations.

    Preventing Race Conditions with Node Taints

    To prevent pods from starting on a node before the EBS CSI Driver is ready, you can use the driver's automatic taint removal feature.

    1. Taint your nodes with ebs.csi.aws.com/agent-not-ready:NoExecute (any effect works, but NoExecute is recommended).
    2. The driver will automatically remove this taint once it is fully operational on the node.
  7. Design requirements for the EBS CSI Driver

    master

    The ebs-plugin is designed around several critical operational requirements to ensure reliability in distributed environments:

    • Idempotency: All CSI calls (e.g., CreateVolume, ControllerPublish, DeleteVolume) must be idempotent. The plugin must check the current state of AWS before acting. For example, CreateVolume should return the existing volume if it was already provisioned, and ControllerPublish should return success if the volume is already attached to the requested node.
    • Timeout Handling: Since gRPC calls can timeout while the underlying AWS operation continues, the driver must be able to handle retries from Kubernetes sidecars. It must check if a previously timed-out operation (like an attachment) actually succeeded before attempting it again.
    • Statelessness/Restarts: The driver is designed to be stateless. Upon restart or crash, it recovers its state by observing the actual status of AWS resources (e.g., describing instances and volumes).
    • Deterministic Device Naming: Because AWS requires the client to assign device names and imposes restrictions on them, the driver assigns device names in a deterministic order and maintains a cache of attempted names that are likely unusable for a specific instance type.
  8. Understand the AWS EBS CSI Driver RPC lifecycle

    master

    The driver operates via two main service types: the Identity Service and the Controller Service, which handle high-level volume management, and the Node Service, which handles local device operations on Kubernetes nodes.

    Identity Service

    Used by Kubernetes to verify driver health and capabilities:

    • GetPluginInfo: Returns driver name (ebs.csi.aws.com) and version.
    • GetPluginCapabilities: Returns supported capabilities like CONTROLLER_SERVICE.
    • Probe: A liveness probe. For the Controller Service, this performs an hourly DescribeAvailabilityZones call to verify networking and authentication.

    Controller Service

    Manages the lifecycle of EBS volumes at the AWS level:

    • CreateVolume: Provisions a new EBS volume. If creating from a snapshot, it uses the provided snapshot ID.
    • DeleteVolume: Deletes an existing volume. It succeeds if the volume is 'available' (not attached) or if the volume is not found. It returns an error if the volume is currently attached.
    • ControllerPublishVolume: Attaches a volume to a node. It selects an unused device name and polls until the volume state is in-use.
    • ControllerUnpublishVolume: Detaches a volume from a node using DetachVolume.
    • ControllerExpandVolume & ControllerModifyVolume: Used to resize volumes or change attributes (IOPS, throughput, type). These calls are coalesced to prevent hitting AWS API cooldowns.
    • CreateSnapshot / DeleteSnapshot / ListSnapshots: Manages EBS snapshots.

    Node Service

    Manages the volume on the specific Kubernetes node:

    • NodeStageVolume: Finds the device, formats it if necessary, runs fsck if already formatted, and mounts it.
    • NodePublishVolume: Performs a bind-mount of the volume.
    • NodeUnstageVolume / NodeUnpublishVolume: Unmounts the volume.
    • NodeExpandVolume: Resizes the filesystem if the underlying volume has been expanded.
    • NodeGetVolumeStats: Returns usage statistics (available, total, used bytes and inodes).
    • NodeGetInfo: Returns the AWS InstanceID and accessible topology (Availability Zone).
  9. How the AWS EBS CSI Driver is architected

    master

    The AWS EBS CSI Driver is composed of two main components deployed on Kubernetes to manage the lifecycle of EBS volumes. It follows the Container Storage Interface (CSI) specification and uses a split architecture to separate Kubernetes resource management from AWS-specific logic.

    • EBS CSI Controller (ebs-csi-controller): A Kubernetes Deployment that watches for storage resource changes (like PVCs). It interacts with the AWS EC2 APIs to create, attach, and delete volumes.
    • EBS CSI Node (ebs-csi-node): A Kubernetes DaemonSet running on every node. It implements the Node Service RPCs, allowing the Kubelet to mount EBS volumes as block devices or filesystems within container workloads.

    To remain CO-agnostic (Container Orchestrator agnostic), the core ebs-plugin container does not interface directly with the Kubernetes API. Instead, it works alongside Kubernetes CSI sidecar containers (such as csi-provisioner, csi-attacher, and csi-resizer) which handle the generic Kubernetes resource watching and translate those changes into standardized CSI RPC calls for the ebs-plugin.

  10. Understand the available CLUSTER_TYPE and TEST_TYPE options

    master

    Scalability tests are defined by the combination of CLUSTER_TYPE and TEST_TYPE.

    CLUSTER_TYPE

    Determines the cluster architecture and node provisioning strategy:

    • pre-allocated: Creates additional worker nodes during setup. By default, it allocates 1 m7a.48xlarge EC2 instance for every 100 StatefulSet replicas.
    • karpenter: Installs Karpenter during setup. Karpenter provisions and deletes worker nodes dynamically during the test run.

    TEST_TYPE

    Determines the specific workload being exercised:

    • scale-sts: Scales a StatefulSet to $REPLICAS, waits for readiness, deletes the StatefulSet, and waits for PV deletion. Tests the full dynamic provisioning lifecycle.
    • expand-and-modify: Creates $REPLICAS volumes and patches PVC capacity/VolumeAttributesClass at a rate of 5 PVCs per second. Tests ControllerExpandVolume and ControllerModifyVolume. Use MODIFY_ONLY=true or EXPAND_ONLY=true to isolate these behaviors.
    • snapshot-volume-scale: Creates $REPLICAS volumes and takes $SNAPSHOTS_PER_VOLUME snapshots of each.
    • volume-lifecycle-churn: Runs $WAVES sequential waves of $REPLICAS short-lived Jobs. Each wave's volumes are torn down while the next wave's volumes are created, simulating concurrent create/attach and detach/delete pressure (e.g., Spark pipelines).
  11. How FIPS 140-3 mode works in the EBS CSI Driver

    master

    The EBS CSI Driver is compiled with GOFIPS140=certified, which embeds Go's certified FIPS 140-3 cryptographic module (CMVP Certificate #5247).

    By default, FIPS mode is disabled (GODEBUG=fips140=off). When you enable it via environment variables, the following behaviors are activated:

    • Integrity Checks: The cryptographic module performs integrity self-checks and known-answer tests at startup.
    • TLS Restrictions: crypto/tls restricts connections to FIPS-approved cipher suites and protocol versions.
    • Randomness: crypto/rand utilizes a NIST SP 800-90A Rev 1 DRBG.
    • AWS Connectivity: The driver uses FIPS-validated API endpoints via the AWS_USE_FIPS_ENDPOINT setting.