<p>we have defined our YAML with</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - image: mcr.microsoft.com/oss/nginx/nginx:1.15.5-alpine
    name: mypod
    volumeMounts:
      - name: azure
        mountPath: /mnt/azure
  volumes:
  - name: azure
    azureFile:
      secretName: azure-secret
      shareName: aksshare
      readOnly: false
</code></pre>
<p>and we will before the deployment create secret with <code>kubectl</code> command:</p>
<pre><code>$AKS_PERS_STORAGE_ACCOUNT_NAME
$STORAGE_KEY

kubectl create secret generic azure-secret --from-literal=azurestorageaccountname=$AKS_PERS_STORAGE_ACCOUNT_NAME \
--from-literal=azurestorageaccountkey=$STORAGE_KEY
</code></pre>
<p>We already have that existing file share as Azure File Share resource and we have file stored in it.</p>
<p>I am confused if we need to manage and define as well yamls for
<code>kind: PersistentVolume</code>
and
<code>kind: PersistentVolumeClaim</code></p>
<p>or the above YAML is completely enough?
Are PV and PVC required only if we do not have our file share already created on Azure?
I've read the docs <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/persistent-volumes/</a> but still feeling confused when they need to be defined and when it is OK not to use them at all during the overall deployment process.</p>

vel
<p>Your Pod Yaml is ok.</p>
<p>The <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">Kubernetes Persistent Volumes</a> is a newer abstraction. If your application instead uses <code>PersistentVolumeClaim</code> it is <strong>decoupled</strong> from the type of storage you use (in your case Azure File Share) so your app can be deployed to e.g. AWS or Google Cloud or Minikube on your desktop without any changes. Your cluster need to have some support for <code>PersistentVolumes</code> and that part can be tied to a specific storage system.</p>
<p>So, to decouple your app yaml from specific infrastructure, it is better to use <code>PersistentVolumeClaims</code>.</p>
<h2>Persistent Volume Example</h2>
<p><em>I don't know about Azure File Share, but there is good documentation on</em> <a href="https://learn.microsoft.com/en-us/azure/aks/azure-files-dynamic-pv" rel="nofollow noreferrer">Dynamically create and use a persistent volume with Azure Files in Azure Kubernetes Service (AKS)</a>.</p>
<h3>Application config</h3>
<p><strong>Persistent Volume Claim</strong></p>
<p>Your app, e.g. a <code>Deployment</code> or <code>StatefulSet</code> can have this PVC resource</p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-azurefile
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: my-azurefile
  resources:
    requests:
      storage: 5Gi
</code></pre>
<p>Then you need to create a <code>StorageClass</code> resource that probably is unique for each type of environment, but need to have the <strong>same name</strong> and support the <strong>same access modes</strong>. If the environment does not support <em>dynamic volume provisioning</em> you may to have manually create <code>PersistentVolume</code> resource as well.</p>
<p>Examples in different environments:</p>
<ul>
<li>The linked doc <a href="https://learn.microsoft.com/en-us/azure/aks/azure-files-dynamic-pv" rel="nofollow noreferrer">Dynamically create and use a persistent volume with Azure Files in AKS)</a> describes for Azure.</li>
<li>See <a href="https://docs.aws.amazon.com/eks/latest/userguide/efs-csi.html" rel="nofollow noreferrer">AWS EFS doc</a> for creating <code>ReadWriteMany</code> volumes in AWS.</li>
<li><a href="http://pietervogelaar.nl/minikube-nfs-mounts" rel="nofollow noreferrer">Blog about ReadWriteMany storage in Minikube</a></li>
</ul>
<p><strong>Pod using Persistent Volume Claim</strong></p>
<p>You typically deploy apps using a <code>Deployment</code> or a <code>StatefulSet</code> but the part declaring the Pod template is similar, except that you probably want to use <code>volumeClaimTemplate</code> instead of <code>PersistentVolumeClaim</code> for <code>StatefulSet</code>.</p>
<p>See full example on <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-pod" rel="nofollow noreferrer">Create a Pod using a PersistentVolumeClaim</a></p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: task-pv-pod
spec:
  volumes:
    - name: file-share
      persistentVolumeClaim:
        claimName: my-azurefile    # this must match your name of PVC
  containers:
    - name: task-pv-container
      image: nginx
      ports:
        - containerPort: 80
          name: &quot;http-server&quot;
      volumeMounts:
        - mountPath: &quot;/usr/share/nginx/html&quot;
          name: file-share
</code></pre>
