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.
Want to run this yourself? Check out the following GitHub repository!
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!
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.