connecting to azure storage using access key in azure kubernetes service

241 Views Asked by At

I am using pip package azure-storage-file-share in my application to get the list of files, connection is done using access_key for storage. It is able to retrieve file information when run locally. When deployed in azure kubernetes service as a docker container. The application is not able to connect to the storage service.

I understand using a managed identity is more better way. but Should it connect even using access_key.

Thanks

1

There are 1 best solutions below

1
On

connecting to azure storage using access key in azure kubernetes service.

You can follow these steps to connect an Azure storage account to Azure Kubernetes using access key.

  1. Here is the yaml file to use the storage secrets.

storage_secret.yaml

apiVersion: v1
kind: Secret
metadata:
  name: storage-secret
  namespace: default
type: Opaque
data:
  azurestorageaccountname: dmVua2F0Njc4
  azurestorageaccountkey: RVA5d1MvdWROVHhSd1BvMGtuU0d6VEhINnJoTENJNHJqeHVCR3ZBczh6dmdxMjh1Y0Z0Y2tmZHNLVHlXN2RuNEVlYWZtRFgwTXdZcytBU3RNR0xFOWc9PQ==

Note: Before applying the YAML, convert the storage account name and access key to base 64 using this tool

  1. Upload a sample image to ACR. I used NGINX as an example.

enter image description here

This YAML file to use an access key to mount an Azure File share on AKS.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-azurestorage-test
  namespace: default
spec:  
  selector:
      matchLabels:
        app: azuretest
  template:
    metadata:
      labels:
        app: azuretest
    spec:
      containers:
      - name: azuretest
        image: acrname.azurecr.io/sampleimage/nginx
        volumeMounts:
        - name: test
          mountPath: /<fileshare Name>   
      volumes:
      - name: <fileshare Name>  
        azureFile:
          secretName: venkat
          shareName: /<fileshare Name>  
          readOnly: false

Save the above code in .yaml extension and then run the following command.

kubectl apply -f fileshare.yaml
kubectl get deployment
kubectl get deployment -o json

The Storage Fileshare was mounted to AKS after executing the kubectl apply command.

enter image description here

enter image description here