{"id":155,"date":"2023-01-01T14:00:14","date_gmt":"2023-01-01T14:00:14","guid":{"rendered":"https:\/\/devopsopen.com\/?p=155"},"modified":"2023-01-22T13:35:04","modified_gmt":"2023-01-22T13:35:04","slug":"storage","status":"publish","type":"post","link":"https:\/\/devopsopen.com\/index.php\/2023\/01\/01\/storage\/","title":{"rendered":"Storage"},"content":{"rendered":"<h1>Storage<\/h1>\n<h4 id=\"Summary\">Summary<\/h4>\n<ul class=\"ez-toc-page-1 ez-toc-heading-level-2\">\n<li><a title=\"Storage in Docker\" href=\"#Storage in Docker\"> Storage in Docker<\/a><\/li>\n<li><a title=\"Volume\" href=\"#Volume\"> Volume<\/a><\/li>\n<li><a title=\"Persistent Volume\" href=\"#Persistent Volume\"> Persistent Volume<\/a><\/li>\n<li><a title=\"Persistent Volume Claim\" href=\"#Persistent Volume Claim\">Persistent Volume Claim<\/a><\/li>\n<li><a title=\"Access Modes for Volumes\" href=\"#Access Modes for Volumes\"> Access Modes for Volumes<\/a><\/li>\n<li><a title=\"Kubernetes Storage Object\" href=\"#Kubernetes Storage Object\"> Kubernetes Storage Object<\/a><\/li>\n<li><a title=\"Configure Applications With Persistent Storage\" href=\"#Configure Applications With Persistent Storage\"> Configure Applications With Persistent Storage<\/a><\/li>\n<\/ul>\n<h2 id=\"Storage in Docker\"><a title=\"Summary\" href=\"#Summary\">Storage in Docker<\/a><\/h2>\n<p>Create a volume in docker :<\/p>\n<p>docker volume create data_volume<\/p>\n<p>This command create a directory in \/var\/lib\/docker\/volumes with the name \/var\/lib\/docker\/volumes\/data_volume<\/p>\n<p>Run \u00e0 container with directory \/var\/lib\/mysql attached to\u00a0 a volume : docker run -v data_volume:\/var\/lib\/mysql mysql<\/p>\n<p>docker run -v data_volume:\/var\/lib\/mysql mysql\u00a0 (mysql\u00a0 is the name of container)<\/p>\n<p>docker run -v data_volume2:\/var\/lib\/mysql mysql<\/p>\n<p>docker run -v \/data\/mysql:\/var\/lib\/mysql mysql<\/p>\n<p>docker run --mount type=bind,source=\/data\/mysql,target=\/var\/lib\/mysql mysql<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-162\" src=\"https:\/\/devopsopen.com\/wp-content\/uploads\/2023\/01\/volumesdocker.png\" alt=\"\" width=\"875\" height=\"456\" srcset=\"https:\/\/devopsopen.com\/wp-content\/uploads\/2023\/01\/volumesdocker.png 1080w, https:\/\/devopsopen.com\/wp-content\/uploads\/2023\/01\/volumesdocker-300x156.png 300w, https:\/\/devopsopen.com\/wp-content\/uploads\/2023\/01\/volumesdocker-1024x534.png 1024w, https:\/\/devopsopen.com\/wp-content\/uploads\/2023\/01\/volumesdocker-768x400.png 768w\" sizes=\"(max-width: 875px) 100vw, 875px\" \/><\/p>\n<ul>\n<li><strong><code class=\"language-plaintext highlighter-rouge\">-v<\/code> or <code class=\"language-plaintext highlighter-rouge\">--volume<\/code><\/strong>: Consists of three fields, separated by colon characters (<code class=\"language-plaintext highlighter-rouge\">:<\/code>). The fields must be in the correct order, and the meaning of each field is not immediately obvious.\n<ul>\n<li>In the case of bind mounts, the first field is the path to the file or directory on the <strong>host machine<\/strong>.<\/li>\n<li>The second field is the path where the file or directory is mounted in the container.<\/li>\n<li>The third field is optional, and is a comma-separated list of options, such as <code class=\"language-plaintext highlighter-rouge\">ro<\/code>, <code class=\"language-plaintext highlighter-rouge\">z<\/code>, and <code class=\"language-plaintext highlighter-rouge\">Z<\/code>. These options are discussed below.<\/li>\n<\/ul>\n<\/li>\n<li><strong><code class=\"language-plaintext highlighter-rouge\">--mount<\/code><\/strong>: Consists of multiple key-value pairs, separated by commas and each consisting of a <code class=\"language-plaintext highlighter-rouge\">&lt;key&gt;=&lt;value&gt;<\/code> tuple. The <code class=\"language-plaintext highlighter-rouge\">--mount<\/code> syntax is more verbose than <code class=\"language-plaintext highlighter-rouge\">-v<\/code> or <code class=\"language-plaintext highlighter-rouge\">--volume<\/code>, but the order of the keys is not significant, and the value of the flag is easier to understand.\n<ul>\n<li>The <code class=\"language-plaintext highlighter-rouge\">type<\/code> of the mount, which can be <code class=\"language-plaintext highlighter-rouge\">bind<\/code>, <code class=\"language-plaintext highlighter-rouge\">volume<\/code>, or <code class=\"language-plaintext highlighter-rouge\">tmpfs<\/code>. This topic discusses bind mounts, so the type is always <code class=\"language-plaintext highlighter-rouge\">bind<\/code>.<\/li>\n<li>The <code class=\"language-plaintext highlighter-rouge\">source<\/code> of the mount. For bind mounts, this is the path to the file or directory on the Docker daemon host. May be specified as <code class=\"language-plaintext highlighter-rouge\">source<\/code> or <code class=\"language-plaintext highlighter-rouge\">src<\/code>.<\/li>\n<li>The <code class=\"language-plaintext highlighter-rouge\">destination<\/code> takes as its value the path where the file or directory is mounted in the container. May be specified as <code class=\"language-plaintext highlighter-rouge\">destination<\/code>, <code class=\"language-plaintext highlighter-rouge\">dst<\/code>, or <code class=\"language-plaintext highlighter-rouge\">target<\/code>.<\/li>\n<li>The <code class=\"language-plaintext highlighter-rouge\">readonly<\/code> option, if present, causes the bind mount to be <a href=\"https:\/\/docs.docker.com\/storage\/bind-mounts\/#use-a-read-only-bind-mount\">mounted into the container as read-only<\/a>.<\/li>\n<li>The <code class=\"language-plaintext highlighter-rouge\">bind-propagation<\/code> option, if present, changes the <a href=\"https:\/\/docs.docker.com\/storage\/bind-mounts\/#configure-bind-propagation\">bind propagation<\/a>. May be one of <code class=\"language-plaintext highlighter-rouge\">rprivate<\/code>, <code class=\"language-plaintext highlighter-rouge\">private<\/code>, <code class=\"language-plaintext highlighter-rouge\">rshared<\/code>, <code class=\"language-plaintext highlighter-rouge\">shared<\/code>, <code class=\"language-plaintext highlighter-rouge\">rslave<\/code>, <code class=\"language-plaintext highlighter-rouge\">slave<\/code>.<\/li>\n<li>The <code class=\"language-plaintext highlighter-rouge\">--mount<\/code> flag does not support <code class=\"language-plaintext highlighter-rouge\">z<\/code> or <code class=\"language-plaintext highlighter-rouge\">Z<\/code> options for modifying selinux labels.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Be attention, -v create the directory for you and not --mount<\/p>\n<p>drivers are responsable to mount all volumes :<\/p>\n<p>AUFS, ZFS, BTRFS, Device Mapper, Overlay, Overlay2 are Storage Drivers<\/p>\n<p>Local, Azur File Storage, Convoy, DigitalOcean Block Storage, Flocker, Gce-Docker, NetAPP, RexRay, Portworx, VMware vSphere Storage are Volume Drivers<\/p>\n<p>command to run docker with volume extern:<\/p>\n<p>docker run -it --name mysql --volume-driver rexray\/ebs --mount src=ebs-vol, target=\/var\/lib\/mysql mysql\u00a0 (amazon ebs)<\/p>\n<h2 id=\"Volume\"><a title=\"Summary\" href=\"#Summary\">Volume<\/a><\/h2>\n<p>Volumes are ephemere and created on the pod. if a pod get down, the volume also and files are destroyed and lost<\/p>\n<p>apiVersion: v1<br \/>kind: Pod<br \/>metadata:<br \/>name: random-number-generator<br \/>spec:<br \/>containers:<br \/>- image: alpine<br \/>name: alpine<br \/>command: [\"\/bin\/sh\",\"-c\"]<br \/>args: [\"shuf -i 0-100 -n 1 &gt;&gt; \/opt\/number.out;\"]<br \/><strong>\u00a0\u00a0\u00a0\u00a0 volumeMounts:<\/strong><br \/><strong>\u00a0\u00a0\u00a0\u00a0\u00a0 - mountPath: \/opt<\/strong><br \/><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 name: data-volume<\/strong><br \/><strong>\u00a0\u00a0\u00a0\u00a0\u00a0 volumes:<\/strong><br \/><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 - name: data-volume <\/strong><br \/><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 hostPath:<\/strong><br \/><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 path: \/data<\/strong><br \/><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 type: Directory<\/strong><\/p>\n<p>The directory \/data is created in evry node in witch the pod is hosted that's why the Volume is detroyed asson as the pod is destroyed by Kubernetes.<\/p>\n<h2 id=\"Persistent Volume\"><a title=\"Summary\" href=\"#Summary\">Persistent Volume<\/a><\/h2>\n<p>The persistant volume is used by the administrator to manage capacity storage of a volume and access mode...<\/p>\n<pre tabindex=\"0\"><code class=\"language-yaml\" data-lang=\"yaml\">apiVersion: v1\nkind: PersistentVolume\nmetadata:\n  name: pv-vol\nspec:\n  capacity:\n    storage: 5Gi\n  accessModes:\n    - ReadWriteOnce\n  hostPath:\n     path: \/tmp\/data<\/code><\/pre>\n<h2 id=\"Persistent Volume Claim\"><a title=\"Summary\" href=\"#Summary\">Persistent Volume Claim<\/a><\/h2>\n<p>persistent volume claim are used by users.<\/p>\n<div class=\"paragraph\">\n<p>A PVC that does not specify a PV name or selector will match any PV.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>To bind a PVC to a specific PV as a cluster administrator:<\/p>\n<\/div>\n<div class=\"ulist\">\n<ul>\n<li>Use <code>pvc.spec.volumeName<\/code> if you know the PV name.<\/li>\n<li>Use <code>pvc.spec.selector<\/code> if you know the PV labels.\n<div class=\"paragraph\">\n<p>By specifying a selector, the PVC requires the PV to have specific labels.<\/p>\n<\/div>\n<\/li>\n<\/ul>\n<\/div>\n<pre tabindex=\"0\"><code class=\"language-yaml\" data-lang=\"yaml\">apiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n  name: myclaim\nspec:\n  accessModes:\n    - ReadWriteOnce\n  volumeMode: Filesystem\n  resources:\n    requests:\n      storage: 8Gi\n  storageClassName: slow\n<\/code><\/pre>\n<h2 id=\"Access Modes for Volumes\"><a title=\"Summary\" href=\"#Summary\">Access Modes for Volumes<\/a><\/h2>\n<ul>\n<li>ReadWriteOnce \u2013 the volume can be mounted as read-write by a single node<\/li>\n<li>ReadOnlyMany \u2013 the volume can be mounted read-only by many nodes<\/li>\n<li>ReadWriteMany \u2013 the volume can be mounted as read-write by many nodes<\/li>\n<li>Kubernetes v1.22 introduced a fourth access mode for PVs and PVCs, that you can use for CSI ReadWriteOncePod \u2013 the volume can be mounted as read-write by a single pod<\/li>\n<\/ul>\n<h2 id=\"Kubernetes Storage Object\"><a title=\"Summary\" href=\"#Summary\">Kubernetes Storage Class<\/a><\/h2>\n<p>StorageClass called Profile in other system let administrator to configure class of a provisionning system , NFS, AWS...<\/p>\n<p>According to the profile you chose: quality of ervice levels, backup policies or determined<\/p>\n<p>You can chose the provisioner,reclaimPolicy,mountoptions and volumeBindingMode<\/p>\n<p>https:\/\/kubernetes.io\/docs\/concepts\/storage\/storage-classes\/<\/p>\n<h2 id=\"Configure Applications With Persistent Storage\"><a title=\"Summary\" href=\"#Summary\">Configure Applications With Persistent Storage<\/a><\/h2>\n<p>\u00a0<\/p>\n\n\n<p>Example of using PersistentVolume with Deployment object<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: v1\nkind: Service\nmetadata:\n  name: wordpress-mysql\n  labels:\n    app: wordpress\nspec:\n  ports:\n    - port: 3306\n  selector:\n    app: wordpress\n    tier: mysql\n  clusterIP: None\n---\napiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n  name: mysql-pv-claim\n  labels:\n    app: wordpress\nspec:\n  accessModes:\n    - ReadWriteOnce\n  resources:\n    requests:\n      storage: 20Gi\n---\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: wordpress-mysql\n  labels:\n    app: wordpress\nspec:\n  selector:\n    matchLabels:\n      app: wordpress\n      tier: mysql\n  strategy:\n    type: Recreate\n  template:\n    metadata:\n      labels:\n        app: wordpress\n        tier: mysql\n    spec:\n      containers:\n      - image: mysql:5.6\n        name: mysql\n        env:\n        - name: MYSQL_ROOT_PASSWORD\n          valueFrom:\n            secretKeyRef:\n              name: mysql-pass\n              key: password\n        ports:\n        - containerPort: 3306\n          name: mysql\n        volumeMounts:\n        - name: mysql-persistent-storage\n          mountPath: \/var\/lib\/mysql\n      volumes:\n      - name: mysql-persistent-storage\n        persistentVolumeClaim:\n          claimName: mysql-pv-claim<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Storage Summary Storage in Docker Volume Persistent Volume Persistent Volume Claim Access Modes for Volumes Kubernetes Storage Object Configure Applications With Persistent Storage Storage in Docker Create a volume in docker : docker volume create data_volume This command create a directory in \/var\/lib\/docker\/volumes with the name \/var\/lib\/docker\/volumes\/data_volume Run \u00e0 container with directory \/var\/lib\/mysql attached to\u00a0 a volume : docker run -v data_volume:\/var\/lib\/mysql mysql docker run -v data_volume:\/var\/lib\/mysql mysql\u00a0 (mysql\u00a0 is the name of container) docker run -v data_volume2:\/var\/lib\/mysql mysql docker run -v \/data\/mysql:\/var\/lib\/mysql mysql docker run &#8211;mount type=bind,source=\/data\/mysql,target=\/var\/lib\/mysql mysql -v or &#8211;volume: Consists of three fields, separated by colon characters\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":""},"categories":[12],"tags":[],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":5}},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"admin","author_link":"https:\/\/devopsopen.com\/index.php\/author\/admin_bak\/"},"uagb_comment_info":2,"uagb_excerpt":"Storage Summary Storage in Docker Volume Persistent Volume Persistent Volume Claim Access Modes for Volumes Kubernetes Storage Object Configure Applications With Persistent Storage Storage in Docker Create a volume in docker : docker volume create data_volume This command create a directory in \/var\/lib\/docker\/volumes with the name \/var\/lib\/docker\/volumes\/data_volume Run \u00e0 container with directory \/var\/lib\/mysql attached to\u00a0&hellip;","_links":{"self":[{"href":"https:\/\/devopsopen.com\/index.php\/wp-json\/wp\/v2\/posts\/155"}],"collection":[{"href":"https:\/\/devopsopen.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devopsopen.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devopsopen.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/devopsopen.com\/index.php\/wp-json\/wp\/v2\/comments?post=155"}],"version-history":[{"count":17,"href":"https:\/\/devopsopen.com\/index.php\/wp-json\/wp\/v2\/posts\/155\/revisions"}],"predecessor-version":[{"id":194,"href":"https:\/\/devopsopen.com\/index.php\/wp-json\/wp\/v2\/posts\/155\/revisions\/194"}],"wp:attachment":[{"href":"https:\/\/devopsopen.com\/index.php\/wp-json\/wp\/v2\/media?parent=155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devopsopen.com\/index.php\/wp-json\/wp\/v2\/categories?post=155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devopsopen.com\/index.php\/wp-json\/wp\/v2\/tags?post=155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}