Help shape GoConqr. What should we add next?

Flashcards

Aron Midgård - 9 Volumes and data

Assar Pettersson English 21 cards

Cards in this deck (21)

  1. 1Introduce VolumesA Pod specification can declare one or more volumes and where they are made available. Each requires a name, a type, and a mount point. The same volume can be made available to multiple containers within a Pod, which can be a method of container-to-container communication. A volume can be made available to multiple Pods, with each given an access mode to write. There is no concurrency checking, which means data corruption is probable, unless outside locking takes place.
  2. 2Kubernetes Pod VolumesA particular access mode is part of a Pod request. As a request, the user may be granted more, but not less access, though a direct match is attempted first. The cluster groups volumes with the same mode together, then sorts volumes by size, from smallest to largest. The claim is checked against each in that access mode group, until a volume of sufficient size matches. The three access modes are:
    ReadWriteOnce, which allows read-write by a single node
    ReadOnlyMany, which allows read-only by multiple nodes
    ReadWriteMany, which allows read-write by many nodes.
  3. 3Volume SpecOne of the many types of storage available is an emptyDir. The kubelet will create the directory in the container, but not mount any storage. Any data created is written to the shared container space. As a result, it would not be persistent storage. When the Pod is destroyed, the directory would be deleted along with the container.
  4. 4Volume TypesSeveral types can be used to define volumes.
    -GCEpersistentDisk
    -awsElasticBlockStore
    -emptyDir and hostPath
    -NFS (Network File System) and iSCSI (Internet Small Computer System Interface) are straightforward choices for multiple readers scenarios.
    -rbd for block storage or CephFS and GlusterFS, if available in your Kubernetes cluster, can be a good choice for multiple writer needs.
  5. 5Shared Volume ExampleThe following YAML file creates a pod, exampleA, with two containers, both with access to a shared volume:
    ....
    containers:
    - name: alphacont
    image: busybox
    volumeMounts:
    - mountPath: /alphadir
    name: sharevol
    - name: betacont
    image: busybox
    volumeMounts:
    - mountPath: /betadir
    name: sharevol
    volumes:
    - name: sharevol
    emptyDir: {}
    $ kubectl exec -ti exampleA -c betacont -- touch /betadir/foobar
    $ kubectl exec -ti exampleA -c alphacont -- ls -l /alphadir
    total 0
    -rw-r--r-- 1 root root 0 Nov 19 16:26 foobar
  6. 6Persistent Volumes and ClaimsA persistent volume (pv) is a storage abstraction used to retain data longer then the Pod using it. Pods define a volume of type persistentVolumeClaim (pvc) with various parameters for size and possibly the type of backend storage known as its StorageClass. The cluster then attaches the persistentVolume.
    Kubernetes will dynamically use volumes that are available, irrespective of its storage type, allowing claims to any backend storage.
  7. 7Persistent Storage Phases - ProvisionProvisioning can be from PVs created in advance by the cluster administrator, or requested from a dynamic source, such as the cloud provide
  8. 8Persistent Storage Phases - BindBinding occurs when a control loop on the master notices the PVC, containing an amount of storage, access request, and optionally, a particular StorageClass. The watcher locates a matching PV or waits for the StorageClass provisioner to create one. The PV must match at least the storage amount requested, but may provide more.
  9. 9Persistent Storage Phases - UseThe use phase begins when the bound volume is mounted for the Pod to use, which continues as long as the Pod requires.
  10. 10Persistent Storage Phases - ReleaseReleasing happens when the Pod is done with the volume and an API request is sent, deleting the PVC. The volume remains in the state from when the claim is deleted until available to a new claim. The resident data remains depending on the persistentVolumeReclaimPolicy.
  11. 11Persistent Storage Phases - ReclaimThe reclaim phase has three options:
    Retain, which keeps the data intact, allowing for an administrator to handle the storage and data.
    Delete tells the volume plugin to delete the API object, as well as the storage behind it.
    The Recycle option runs an rm -rf /mountpoint and then makes it available to a new claim. With the stability of dynamic provisioning, the Recycle option is planned to be deprecated.
  12. 12Persistent volumePersistent volumes are not a namespaces object, but persistent volume claims are. A beta feature of v1.13 allows for static provisioning of Raw Block Volumes, which currently support the Fibre Channel plugin, AWS EBS, Azure Disk and RBD plugins among others.
  13. 13Persistent Volume ClaimWith a persistent volume created in your cluster, you can then write a manifest for a claim, and use that claim in your pod definition. In the Pod, the volume uses the persistentVolumeClaim.
  14. 14Dynamic ProvisioningWhile handling volumes with a persistent volume definition and abstracting the storage provider using a claim is powerful, a cluster administrator still needs to create those volumes in the first place. Starting with Kubernetes v1.4, Dynamic Provisioning allowed for the cluster to request storage from an exterior, pre-configured source. API calls made by the appropriate plugin allow for a wide range of dynamic storage use.
    The StorageClass API resource allows an administrator to define a persistent volume provisioner of a certain type, passing storage-specific parameters.
    With a StorageClass created, a user can request a claim, which the API Server fills via auto-provisioning. The resource will also be reclaimed as configured by the provider. AWS and GCE are common choices for dynamic storage, but other options exist, such as a Ceph cluster or iSCSI. Single, default class is possible via annotation.
  15. 15Using Rook for Storage Orchestrationn keeping with the decoupled and distributed nature of the Cloud technology, the Rook project allows orchestration of storage using multiple storage providers.
    As with other agents of the cluster, Rook uses custom resource definitions (CRD) and a custom operator to provision storage according to the backend storage type, upon API call.
    Several storage providers are supported:
    Ceph
    Cassandra
    CockroachDB
    EdgeFS Geo-Transparant Storage
    Minio Object Store
    Network File System (NFS)
    YugabyteDB.
  16. 16SecretsPods can access local data using volumes, but there is some data you don't want readable to the naked eye. Passwords may be an example. Using the Secret API resource, the same password could be encoded or encrypted.
    A secret is not encrypted, only base64-encoded, by default. You must create an EncryptionConfiguration with a key and proper identity. Then, the kube-apiserver needs the --encryption-provider-config flag set to a previously configured provider, such as aescbc or ksm. Once this is enabled, you need to recreate every secret, as they are encrypted upon write.
    Multiple keys are possible. Each key for a provider is tried during decryption. The first key of the first provider is used for encryption. To rotate keys, first create a new key, restart (all) kube-apiserver processes, then recreate every secret.
    You can see the encoded string inside the secret with kubectl. The secret will be decoded and be presented as a string saved to a file. The file can be used as an environmental variable or in a new directory, similar to the presentation of a volume.
  17. 17Using Secrets via Environment VariablesA secret can be used as an environmental variable in a Pod. You can see one being configured in the following example:
    ...
    spec:
    containers:
    - image: mysql:5.5
    env:
    - name: MYSQL_ROOT_PASSWORD
    valueFrom:
    secretKeyRef:
    name: mysql
    key: password
    name: mysql
    There is no limit to the number of Secrets used, but there is a 1MB limit to their size. Each secret occupies memory, along with other API objects, so very large numbers of secrets could deplete memory on a host.
    They are stored in the tmpfs storage on the host node, and are only sent to the host running Pod. All volumes requested by a Pod must be mounted before the containers within the Pod are started. So, a secret must exist prior to being requested.
  18. 18Mounting Secrets as VolumesYou can also mount secrets as files using a volume definition in a pod manifest. The mount path will contain a file whose name will be the key of the secret created with the kubectl create secret step earlier.
  19. 19Portable Data with ConfigMapssimilar API resource to Secrets is the ConfigMap, except the data is not encoded. In keeping with the concept of decoupling in Kubernetes, using a ConfigMap decouples a container image from configuration artifacts.
    They store data as sets of key-value pairs or plain configuration files in any format. The data can come from a collection of files or all files in a directory. It can also be populated from a literal value.
    A ConfigMap can be used in several different ways. A container can use the data as environmental variables from one or more sources. The values contained inside can be passed to commands inside the pod. A Volume or a file in a Volume can be created, including different names and particular access modes. In addition, cluster components like controllers can use the data. ​
    Let's say you have a file on your local filesystem called config.js. You can create a ConfigMap that contains this file. The configmap object will have a data section containing the content of the file:
  20. 20Using ConfigMapsLike secrets, you can use ConfigMaps as environment variables or using a volume mount. They must exist prior to being used by a Pod, unless marked as optional. They also reside in a specific namespace.
    In the case of environment variables, your pod manifest will use the valueFrom key and the configMapKeyRef value to read the values. For instance:
    env:
    - name: SPECIAL_LEVEL_KEY
    valueFrom:
    configMapKeyRef:
    name: special-config
    key: special.how
    With volumes, you define a volume with the configMap type in your pod and mount it where it needs to be used.
    volumes:
    - name: config-volume
    configMap:
    name: special-config
  21. 21—

Information

Description
Flashcards on Aron Midgård - 9 Volumes and data, created by Assar Pettersson on 12/05/2020.
Views
5
Rating

More on Kubernetes

Feedback

What is it about?

What should we add next?