Bobcares

Mount Azure File Share Kubernetes | How to?

by | Jul 27, 2022

Read this article to follow the simple method from our Support team to mount Azure File Share on Kubernetes.

Bobcares, as part of our Server Management service, offers solutions to every query that comes our way.

Let’s take a closer look at mounting Azure File Share on Kubernetes. Get in touch with us if you have any further inquiries.

Mount Azure File Share To Kubernetes

A mounted Azure file share can be shared across multiple containers in Microsoft’s hosted Kubernetes offering, AKS. In this article, we will see the instructions from our Expert team that guide the users through the process step by step.

We must have an active Azure Kubernetes Services cluster and an Azure Storage account before we can begin.

Make An Azure File Share

We can simply make an Azure file share with Azure Portal. Follow the below steps:

  1. Create the Azure File share: Find the Files menu item on the left side of the Storage Account we want to use in the Azure Portal, click the + File share button, and give it a name.
  2. Gather the connection information: Go to the Storage Account’s Access Keys section in the Azure Portal to view the details.
  3. Base64 encrypts the connection information for the Kubernetes Secret: We can do Base64 encoding with code, PowerShell, or online websites. We advise not to use online sites as we are unaware of their database management. For ease, we can use Powershell to base64 and encode the values.

Define And Deploy To Kubernetes In AKS

Firstly, we need to create a new namespace for our deployment in order to define and deploy to Kubernetes. Then make a secret that contains the information necessary to connect to our Storage account. Lastly, we create a deployment that mounts the Azure File share on the containers and deploys our image.

  1. To create a Kubernetes namespace: This is an optional step that depends on the scenario and infrastructure whether we need it or not. Firstly, we need to define it. We can use the below code.  Define demo-namespace.json:
    {
        "kind": "Namespace",
        "apiVersion": "v1",
        "metadata": {
          "name": "demodeployments",
          "labels": {
            "name": "demodeployments"
          }
        }
      }
    

    Then we can create it with kubectl using the command:

    kubectl create -f demo-namespace.json

    Now, this creates a Kubernetes namespace.

  2. Using the Azure Storage connection information, create a Kubernetes Secret: Firstly, define secret-sauce.yaml with the below code.
    apiVersion: v1
    kind: Secret
    metadata:
      name: storage-secret
      namespace: demodeployments
    type: Opaque
    data:
      azurestorageaccountname: Base64_Encoded_Value_Here
      azurestorageaccountkey: Base64_Encoded_Value_Here

    Then create the secret in the cluster using the below code.

    > kubectl create -f secret-sauce.yaml

    Finally, verify that the secret exists.

    > kubectl get secret storage-secret -n blogdemodeployments
  3. To create Kubernetes Deployment and define the volume mounts: Now we have to create a new deployment that mounts the Azure File share to the containers. Let’s see an example deployment.
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: deployment-azurestorage-test
      namespace: demodeployments
    spec:  
      selector:
          matchLabels:
            app: azuretest
      template:
        metadata:
          labels:
            app: azuretest
        spec:
          containers:
          - name: azuretest
            image: your-registry.azurecr.io/demoapp:latest
            volumeMounts:
            - name: azurefileshare
              mountPath: /myawesomefileshare
          imagePullSecrets:
          - name: your-pull-secret-if-you-have-one       
          volumes:
          - name: azurefileshare
            azureFile:
              secretName: storage-secret
              shareName: myawesomefileshare
              readOnly: false
    

    volumeMounts and volumes are two things we must keep in mind while deployment. In the volumeMounts, we specify the path we want to mount the file share inside the container. The azureFile entry with the secret name is defined by volumes.

  4. Verifying volume mounts in the Kubernetes Deployment: Now we also have to verify that the mounts exist. So to confirm, we use the below code.
    kubectl get deploy -n demodeployments -o json

[Seeking answers to another query? We are just a click away.]

Conclusion

In this article, our Tech team helps us to share a mounted Azure file share across multiple containers in the deployments in Kubernetes which primarily includes making an Azure file share.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.