Introduction
Today’s post is a brief one… Though it packs some punch! In the past I talked about storage patterns for docker/containers. Today we’ll touch how you can leverage the Azure File Storage as a shared & persistent storage for your container deployments. Kubernetes has been gaining a lot of traction, and that one has support for the Azure File Storage as a persistent volume too.
Demo Files
Want to run this yourself? Check out the following GitHub repository!
Brief Demo
So I’ve deployed a kubernetes cluster (via Azure Container Service) and setup my kubectl. Now let’s start deploying our service… In the yaml description, you can see the part describing our volumes ;
apiVersion: v1 kind: Service metadata: name: wordpress labels: app: wordpress spec: ports: - port: 80 selector: app: wordpress tier: frontend type: LoadBalancer --- apiVersion: v1 kind: PersistentVolume metadata: name: pv002 spec: capacity: storage: 5Gi accessModes: - ReadWriteOnce azureFile: secretName: azure-secret shareName: wordpress readOnly: false claimRef: namespace: default name: az-files-02 --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: az-files-02 spec: accessModes: - ReadWriteOnce resources: requests: storage: 5Gi --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: wordpress labels: app: wordpress spec: strategy: type: Recreate template: metadata: labels: app: wordpress tier: frontend spec: containers: - image: wordpress:4.7.3-apache name: wordpress env: - name: WORDPRESS_DB_USER value: my-user-name - name: WORDPRESS_DB_HOST value: my-host-name - name: WORDPRESS_DB_PASSWORD valueFrom: secretKeyRef: name: mysql-secret key: password ports: - containerPort: 80 name: wordpress volumeMounts: - name: wordpress-persistent-storage mountPath: /var/www/html volumes: - name: wordpress-persistent-storage persistentVolumeClaim: claimName: az-files-02
So that is the magic that we’ll use to create a shared volume… Now let’s deploy this shall we?
What happened here? Our service was deployed. Everything went fine. And you’ll also notice that ACS (Azure Container Service) went back to Azure and created the loadbalancer & external ip!
How cool is that?!? Now let’s check the storage account… and we’ll see that wordpress has started adding files.
Checking our Kubernetes dashboard, the deployment looks good too…
And finally, the WordPress installation is showing on our exposed IP!
Closing Thoughts
I’ve often said that Azure Storage is often given the credit it deserves. It’s a service that truly provides you with a lot of flexibility in creating solutions.
What happens when you stop you deployment and delete the PVC? Will the persistent storage/volume remain?
If I then wanted to restart the deployment, how can I ensure it reuses the same persistent storage?
I’m interested in the maintaining my data between Kubernetes cluster restarts.
That is the main purpose of the persistent volumes (PV). You might want to check up on these documentation pages ; https://kubernetes.io/docs/concepts/storage/persistent-volumes/ & https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/
I think Stateful sets is what I really want. Their use of PVs match how I want to use them. Thanks.
How is the performance of such a volume? I mean every time a pod access a file in a volume, it´s a remote access?
I uploaded some GBs to an azure file storage once, and it seemed very slow.
Azure Files currentlty has a limit of 1000 iops & 60mb/s per share.
Source : https://docs.microsoft.com/en-us/azure/azure-subscription-service-limits#storage-limits
A performance boost is due / on the roadmap though. Bare with… or use disks as a pv if suitable.
Hi i am getting this error when i try to do persistent volumes.
MountVolume.SetUp failed for volume “pv002” : exit status 1
Error syncing pod
Check the logs for other hints. My guess is that your secret is missing/incorrect.
i checked the secret all looks good.
in status: Waiting: ContainerCreating
and error below.
MountVolume.SetUp failed for volume “pv002” : exit status 1
Error syncing pod
whr can i check the logs before a container starts.
It’ll be a troubleshooting path then… => https://kubernetes.io/docs/tasks/debug-application-cluster/determine-reason-pod-failure/
Good luck!
I get the CreateContainerConfigError error when I did “kubectl create -f wordpress.yml”. Then, when I did kubectl describe pods. There were two failed events. Couldn’t find key “Password” in Secret default/mysql-secret and Error syncing pod. Can you help? Thanks
Did you create the secrets? It seems you didn’t…
Hi,
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known