In the previous article in this Devops series, we looked at deploying a production ready Kubernetres cluster on Azure using the 'KubeSpray' project. Having set that up, the next step is to make some data storage resources available to the cluster. We do this by creating an Azure file storage resource, and then linking it to the Kubernetes cluster using 'Secrets'. This article is a walk-through of the process.
I can't really think of any reasonable project I've been involved in that didnt have the use of some data storage facility. When you head intot he world of cloud, and containers, having a handy C:\ or D:z\ drive at your fingertips gets elusive. You start having to think of things like persistant volumes and cloud based blob storage and the like. Using Kubernetes, we can set up a data volume that appears to our container resources just like another large remote drive. This is a key piece of the puzzle when pulling different technologies together in an orchestrated manner like we are doing in this series of articles.
Setting up a Kubernetes data volume on Azure
(1) In your control panel, from NEW action, select general storage resource
(2) give the resource a new unique name (lowercase), and use the same resource group as your main Kubernetes cluster
(3) the new resource will become available in the resource group - select it for editing
(4) in the details page, select the 'file' share section
(5) n the file share page, click add-new, give the share a unique name, and specify the size of file storage you require (in GB)
After saving, you should see the newly created share available for use.
(6) Next we need to get some security keys from the storage account.
Go back to the main resource group list where the account is located and select it.
(7) Once in the storage account, we then need to navigate to the 'Access keys' section and copy out the first key and the resource name.
(8) We cant use these keys directly in kubernetes and need to convert them using Base64. We can do this by taking each one of the items we copied and encoding. In this example we use the online resource www.base64encode.org
(9) We now need to take this information and give it to Kubernetes in a Yaml file.
SSH into the main Kubernetes master machine, and issue the following commands:
sudo su -
apt-get install -y cifs-utils
Now use nano to create a new yaml file:
Into this file, add the following contents, *replacing* the value for accountname and accountkey with the base64 encoded values of each (be careful with indenting/spacing in yaml files)
azurestorageaccountname: <your encoded account name>
azurestorageaccountkey: <your encoded key>
After making the changes, use CTRL + O <enter> to write the file, then CTRL + X to exit
This has set up the 'key secret' file, now we need to set up the main instruction file. In this case it has been called 'azure.yaml' but it can be given any name.
The contents of this file are as follows:
- image: kubernetes/pause
- name: azure
- name: azure
- The important parts that you need to change are:
- volumeMounts - given name of 'azure' and an internal virtual mount path. The name should match the name of the volume (next step/file-entry)
- volumes → name → this has been set to a default name of 'azure'. The next entry is 'azureFile' (defines the type of storage volume to Kubernetes). The 'secretName' refers to the data in the 'azure-secret.yaml' file we created earlier, and the shareName is the name we gave to the file share we created in step (5). Setting readONly to false makes the volume available as read/write.
(10) We now need to pass the secret key to Kubernetes and then set the volume running.
At the command line, send in the following command:
kubectl create -f azure-secret.yaml
Once that has completed, the secret has been set, so we can send in the command to setup the volume itself.
kubectl create -f azure.yaml
Once that completes, we can then test that everything has been setup correctly by examining available pods
kubectl get po
This will show an output like the following
Finally we can examine how the volume has been implemented to confirm it is as specified
kubectl describe po azure
Looking at the output of 'describe' you can see important information such as the node (VM) the containers is hosted on, the fact that it is a 'secret based' volume, and that it is connected to an Azure file service.
(11) The volume can now be directly accessed by any container .. we will cover how to do this in detail in a later article.
If you need them, I have put a shortened version of the instructions in a zip attached to the top of thie article. Finally, as usual, if you found the article useful, please give it a vote!
Links of Interest
7/Dec/2017 - Version 1