Learn Storage (CKA) with Interactive Flashcards
Master key concepts in Storage through our interactive flashcard system. Click on each card to reveal detailed explanations and enhance your understanding.
Implement storage classes and dynamic volume provisioning
In the context of the CKA exam, implementing storage classes and dynamic volume provisioning shifts storage management from a manual, static process to an automated, on-demand workflow.
Traditionally, administrators practiced **Static Provisioning**, where they manually created `PersistentVolume` (PV) objects representing physical disks before a developer could claim them. This created an administrative bottleneck. **Dynamic Volume Provisioning** solves this by allowing storage volumes to be created on-demand using a **`StorageClass`**.
A `StorageClass` acts as a template or profile for storage (e.g., 'gold' for fast SSDs, 'silver' for HDDs). To implement this, you define a YAML manifest with:
1. **Provisioner**: The plugin that handles volume creation (e.g., a Cloud Provider or CSI driver).
2. **Parameters**: Backend-specific details (e.g., disk type `gp2`, IOPS).
3. **ReclaimPolicy**: Usually set to `Delete` or `Retain`, dictating what happens to the volume when the claim is deleted.
The workflow occurs as follows: The administrator creates the `StorageClass`. A user then creates a `PersistentVolumeClaim` (PVC) that references the class via the `storageClassName` field. The Kubernetes control plane detects this claim, communicates with the storage provider to provision the disk, automatically creates the PV object, and binds it to the PVC.
For the exam, remember that if `storageClassName` is omitted in a PVC, the cluster's **Default StorageClass** (marked via the annotation `storageclass.kubernetes.io/is-default-class: "true"`) is used. If set to an empty string (`""`), dynamic provisioning is disabled. Mastering this ensures scalable, self-service storage for stateful workloads.
Configure volume types, access modes and reclaim policies
In the Certified Kubernetes Administrator (CKA) curriculum, managing storage requires configuring PersistentVolumes (PVs) to ensure data persists and interacts correctly with Pods via PersistentVolumeClaims (PVCs).
**Volume Types**: Kubernetes supports various storage backends defined in the PV manifest. These range from cloud-provider specific block storage (e.g., `awsElasticBlockStore`, `azureDisk`, `gcePersistentDisk`) to network file systems (`nfs`) and local node storage (`hostPath`). The Container Storage Interface (`csi`) is the modern standard for integrating third-party storage drivers. Configuration involves defining the specific plugin fields in the PV `spec` to match the underlying infrastructure.
**Access Modes**: Defined under `spec.accessModes`, these dictate how the volume can be mounted by nodes. `ReadWriteOnce` (RWO) allows the volume to be mounted as read-write by a single node. `ReadOnlyMany` (ROX) allows multiple nodes to mount it read-only. `ReadWriteMany` (RWX) allows multiple nodes to mount it read-write (typically required for NFS). Note that the volume type determines which modes are valid; for instance, standard block storage usually only supports RWO.
**Reclaim Policies**: The `spec.persistentVolumeReclaimPolicy` determines the fate of the PV after the bound PVC is deleted. `Retain` preserves the PV and its data, requiring manual administrative cleanup. `Delete` automatically removes both the PV object and the external storage asset (common in dynamic provisioning). `Recycle` (deprecated) performs a basic data scrub to make the volume available again.
Administrators configure these settings via YAML files. Additionally, `StorageClasses` are used to define these parameters for dynamic provisioning, ensuring new volumes are created with the specific type and reclaim policy automatically.
Manage persistent volumes and persistent volume claims
In the context of the Certified Kubernetes Administrator (CKA) exam, managing storage revolves around decoupling the physical storage infrastructure from the applications that consume it. This is achieved through two primary API objects: Persistent Volumes (PV) and Persistent Volume Claims (PVC).
A Persistent Volume (PV) is a cluster-resource representing a piece of storage in the cluster. It is provisioned either statically by an administrator or dynamically using a StorageClass. A PV exists independently of any Pod lifecycle and captures the details of the implementation, such as NFS, iSCSI, or cloud-specific storage systems (e.g., AWS EBS). Key configuration parameters include capacity, access modes (ReadWriteOnce, ReadWriteMany, ReadOnlyMany), and the Reclaim Policy (Retain, Recycle, Delete), which determines what happens to the volume when the claim is released.
A Persistent Volume Claim (PVC) is a request for storage by a user or developer. Similar to how a Pod consumes node resources like CPU and memory, a PVC consumes PV resources. The PVC specifies the desired capacity, access modes, and optionally a StorageClass.
The interaction between them is called 'binding'. The Kubernetes control plane watches for new PVCs and looks for a matching PV. If a PV satisfies the PVC's requirements (size and access mode), they are bound together one-to-one. If no static PV matches, dynamic provisioning can create one automatically if a StorageClass is defined. Finally, Pods access this storage by referencing the PVC in their `volumes` section, mounting it into the container's file system. For the exam, you must be proficient in writing these YAML manifests and troubleshooting binding failures, often caused by mismatched access modes or capacity.
StorageClass parameters and provisioners
In the context of the Certified Kubernetes Administrator (CKA) exam, a StorageClass is a critical API resource that enables dynamic volume provisioning, eliminating the need for administrators to manually create PersistentVolumes (PVs) beforehand.
The **provisioner** is a mandatory field that defines which volume plugin handles the actual storage creation. Kubernetes ships with internal provisioners (e.g., `kubernetes.io/aws-ebs`, `kubernetes.io/gce-pd`) and supports external ones via the Container Storage Interface (CSI). When a PersistentVolumeClaim (PVC) requests a specific StorageClass, this provisioner acts as the backend logic to allocate the physical storage resource.
**Parameters** are key-value pairs specified in the `parameters` section. These are opaque to Kubernetes itself and are meant strictly for the specific provisioner. For instance, an AWS provisioner understands parameters like `type: gp3` or `encrypted: "true"`, whereas an Azure Disk provisioner expects `storageaccounttype`. Defining incorrect parameters will cause the provisioning process to hang or fail.
Two other critical configurations often tested are `reclaimPolicy` and `volumeBindingMode`. The **ReclaimPolicy** (usually defaulting to `Delete` or `Retain`) dictates the fate of the PV when the claiming PVC is deleted. **VolumeBindingMode** controls the timing of provisioning. The default `Immediate` creates the volume instantly, but `WaitForFirstConsumer` delays creation until a Pod using the PVC is scheduled. This delay is essential in multi-zone environments to ensure the storage is provisioned in the same availability zone as the node running the Pod, preventing topology conflicts.
Volume expansion and resizing
In the context of the Certified Kubernetes Administrator (CKA) exam, volume expansion is a critical capability for managing stateful workloads that outgrow their initial storage provisioning. Kubernetes allows you to resize Persistent Volume Claims (PVCs) dynamically, but this relies heavily on the specific Container Storage Interface (CSI) driver and the configuration of the StorageClass.
First, the prerequisite: The `StorageClass` associated with the volume must have the parameter `allowVolumeExpansion: true`. If this is not set, the API server will reject updates to the storage size.
To resize a volume, you simply edit the PVC manifest (e.g., via `kubectl edit` or `kubectl apply`) and increase the `spec.resources.requests.storage` value. It is important to note that Kubernetes generally only supports expanding volumes; you cannot shrink a PVC to a smaller size.
Once the request is submitted, two distinct operations occur:
1. **Volume Resizing:** The cloud provider or storage backend increases the physical disk size (control plane operation).
2. **File System Resizing:** The file system (e.g., ext4, xfs) inside the volume must grow to fill the new space (node operation).
Modern CSI drivers often support **Online Expansion**, meaning the file system resizes automatically while the Pod is still running and the volume is mounted. However, if the storage provider only supports **Offline Expansion**, the PVC status might change to `FileSystemResizePending`. In this scenario, you must delete the Pod to detach the volume. When the Pod is recreated, the kubelet will perform the file system expansion during the mount process. For the CKA, always verify the StorageClass capabilities and check PVC conditions to determine if a pod restart is required.
Volume snapshots and cloning
In the context of the Certified Kubernetes Administrator (CKA) exam and Kubernetes storage management, Volume Snapshots and Cloning are critical features enabled by the Container Storage Interface (CSI). They facilitate data backup, disaster recovery, and environment replication.
**Volume Snapshots** allow you to create a copy of a volume at a specific point in time. This process utilizes three specific API resources:
1. **VolumeSnapshotClass:** Defines the specific CSI driver and parameters required, similar to a StorageClass.
2. **VolumeSnapshot:** A namespaced object representing a user's request to snapshot a specific PersistentVolumeClaim (PVC).
3. **VolumeSnapshotContent:** The actual handle to the snapshot on the storage backend.
To restore data, you create a new PVC manifest and specify the `dataSource` field to point to an existing `VolumeSnapshot` object. This provisions a new volume pre-loaded with the snapshot's data.
**Volume Cloning** allows you to create a new PVC populated with data from an existing, active PVC. While snapshots are often used for backups (potentially stored off-site), cloning is typically used to duplicate data for testing or debugging within the same cluster. To clone a volume, you define a new PVC and set the `dataSource` field to point to the *source PVC* name. The source PVC must be in the same namespace and the CSI driver must support volume cloning.
For the CKA, it is essential to understand that these features require a compatible CSI driver (not legacy in-tree drivers). You must be proficient in creating the YAML manifests to trigger a snapshot, restore from a snapshot, and clone a volume using the `dataSource` parameter.
CSI drivers and storage backends
In the context of the Certified Kubernetes Administrator (CKA) exam, understanding the Container Storage Interface (CSI) is essential for managing persistent data. Historically, storage plugins were 'in-tree,' meaning the code to connect to providers like AWS EBS was part of the core Kubernetes binary. This was inefficient and difficult to maintain. The CSI standard solves this by decoupling storage implementation from the Kubernetes core.
**CSI Drivers** are software plugins developed by storage vendors that adhere to the CSI specification. They act as a translation layer between the Kubernetes API and the underlying storage infrastructure. Typically deployed as a combination of a Deployment (for the controller) and a DaemonSet (for node-specific operations like mounting), the driver handles volume provisioning, attaching, and mounting dynamically.
**Storage Backends** represent the actual systems where data resides. These can be cloud-native block storage (AWS EBS, Azure Disk), network-attached storage (NFS), or software-defined solutions (Ceph, GlusterFS). The backend handles the physical data retention, while the CSI driver exposes that backend's capabilities to the cluster.
For a CKA administrator, the critical link is the **StorageClass**. When you define a StorageClass, the `provisioner` field specifies the name of the registered CSI driver (e.g., `kubernetes.io/aws-ebs` or a custom vendor string). When a user submits a PersistentVolumeClaim (PVC), Kubernetes communicates with the specified CSI driver to provision the volume on the backend and mount it to the correct node. This architecture ensures that Kubernetes is extensible and that storage vendors can release patches or features independently of Kubernetes release cycles.
EmptyDir, HostPath and local volumes
In the context of the Certified Kubernetes Administrator (CKA) exam, understanding the lifecycle and scheduling implications of these storage types is vital.
**1. emptyDir**
This is ephemeral storage tied strictly to the lifecycle of a Pod. It is created when a Pod is assigned to a Node and initially contains no data. While data survives container crashes, it is permanently deleted if the Pod is removed or rescheduled. It is primarily used for temporary scratch space, caching, or sharing files between multiple containers within the same Pod.
**2. hostPath**
This volume mounts a specific file or directory from the host Node's filesystem directly into the Pod. It allows a Pod to interact with the underlying host, making it useful for system agents (e.g., monitoring or logging tools accessing `/var/log`). However, it poses security risks and creates a tight coupling to a specific node; if the Pod is rescheduled to a node where the path does not exist, it will fail.
**3. Local Volumes**
A Local PersistentVolume represents a local disk, partition, or directory on a specific Node. Unlike `hostPath`, the Kubernetes scheduler is aware of the Local volume's constraints. It utilizes Volume Node Affinity to ensure the Pod is always scheduled on the exact Node where the storage resides. This makes Local volumes suitable for high-performance, durable storage (like distributed databases) that require low latency but need the scheduler to handle node-pinning logic automatically.