Azure disk examples (#87)

* add azure-disk-examples

* fix according to review comments
This commit is contained in:
Andy Zhang 2017-10-10 23:39:56 +08:00 committed by Ahmet Alp Balkan
parent dab26b5a82
commit 1fd5c2d6f9
19 changed files with 340 additions and 0 deletions

View File

@ -0,0 +1,94 @@
# Kubernetes Persistent Volume Plugin For Blob and Managed Disks Samples
This repo contains samples that works with the new Azure persistent volume plugin for Kubernetes. The plugin is expected to be in v1.7.2 release then will become part of Azure ACS
## What does the plugin do?
1. Provision PVC based on Azure Managed Disks and Blob Disks
2. Perform consistent attach/detach/mount/unmount and format when needed for disks
3. Supports both standard and premium LRS storage accounts.
## Get Started
### Using the Samples
The sequence of events is generally
1. Create a storage class
2. Create a PVC
3. Create a pod or a replication controller that uses the PVC
```
# you can use the following command to create a storage class first
kubectl create -f storageclass-managed-hdd.yaml
# you can use the following command to create a pvc, which will create an azure disk
kubectl create -f pvc-on-managed-hdd.yaml
# You can get more details about the created PVC by
kubectl describe pvc {pvc-name}
# you can use the following command to create a pod with specified pvc
kubectl create -f pod-uses-managed-hdd.yaml
```
To verify, inside of the pod/container, you should see something like this:
```
$ df -h
/dev/sdc                125.9G     59.6M    119.4G   0% /mnt/managed
```
## How does it work?
### Managed Disks
The entire experience is offloaded to Azure to manage disks:storage accounts. You can use PVC (Kubernetes will automatically create a managed disk for you). Or you can you use an existing disk as PV in your PODs/RCs
> Note: as a general rule, use PV disks provisioned in the same Azure resource group where the cluster is provisioned.
### Blob Disks
Blob Disks works in two modes. Controlled by #kind# parameter on the storage class.
### Dedicated (default mode)
When *kind* parameter is set to *dedicated* K8S will create a new dedicated storage account for this new disk. No other disks will be allowed in the this storage account. The account will be removed when the PVC is removed (according to K8S PVC reclaim policy)
> Note: You can still use existing VHDs, again the general rule apply use storage accounts that are part of cluster resource group
### The following storage parameter can be used to control the behaviour
1. *skuname* or *storageaccounttype* to choose the underlying Azure storage account (default is *Standard_LRS* allowed values are *Standard_LRS* and *Premium_LRS*)
2. *cachingmode* controls Azure caching mode when the disk is attached to a VM (default is *readwrite* allowed values are *none*, *readwrite* and *readonly*
3. *kind* decides on disk kind (default is *shared* allowed values are *shared*, *dedicated* and *managed*)
4. *fstype* the file system of this disk (default *ext4*)
### Shared
PVC: VHDs are created in a shared storage accounts in the same resource group as the cluster as the following
```
Resource Group
--Storage Account: pvc{unique-hash}001 // created by K8S as it provisoned PVC, all disks are placed in the same blob container
---pvc-xxx-xxx-xxxx.vhd
---pvc-xxx-xxx-xxxx.vhd
--Storage Account: pvc{unique-hash}002..n
---pvc-xxx-xxx-xxxx.vhd
```
The following rules apply:
1. Maximum # of accounts created by K8S for shared PVC is **100**.
2. Maximum # of disks per account is 60 (VHDs).
3. K8S will create new account for new disks if * utilization(AccountType(NEWDISK)) > 50% * keeping total # of accounts below 100.
4. K8S will create initial 2 accounts ( 1 standard and 1 premium ) to accelerate the provisioning process.
## Additional Notes
The samples assumes that you have a cluster with node labeled with #disktype=blob# for VMs that are using blob disks and #disktype=managed# for VMs that are using managed disks. You can label your nodes or remove the node selector before using the files.
> Note: You can not attach managed disks to VMs that are not using managed OS disks. This applies also the other way around no blob disks on VMS that are using managed OS disks
To label your nodes use the following command
```
kubectl label nodes {node-name-here} disktype=blob
```

View File

@ -0,0 +1,21 @@
kind: Pod
apiVersion: v1
metadata:
name: pod-uses-account-hdd-5g
labels:
name: storage
spec:
containers:
- image: nginx
name: az-c-01
command:
- /bin/sh
- -c
- while true; do echo $(date) >> /mnt/blobdisk/outfile; sleep 1; done
volumeMounts:
- name: blobdisk01
mountPath: /mnt/blobdisk
volumes:
- name: blobdisk01
persistentVolumeClaim:
claimName: pv-dd-account-hdd-5g

View File

@ -0,0 +1,12 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pv-dd-account-hdd-5g
annotations:
volume.beta.kubernetes.io/storage-class: accounthdd
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi

View File

@ -0,0 +1,9 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
name: accounthdd
provisioner: kubernetes.io/azure-disk
parameters:
skuname: Standard_LRS
location: westus
storageAccount: azuretestx

View File

@ -0,0 +1,21 @@
kind: Pod
apiVersion: v1
metadata:
name: pod-uses-dedicated-hdd-5g
labels:
name: storage
spec:
containers:
- image: nginx
name: az-c-01
command:
- /bin/sh
- -c
- while true; do echo $(date) >> /mnt/blobdisk/outfile; sleep 1; done
volumeMounts:
- name: blobdisk01
mountPath: /mnt/blobdisk
volumes:
- name: blobdisk01
persistentVolumeClaim:
claimName: pv-dd-dedicated-hdd-5g

View File

@ -0,0 +1,12 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pv-dd-dedicated-hdd-5g
annotations:
volume.beta.kubernetes.io/storage-class: dedicatedhdd
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi

View File

@ -0,0 +1,7 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
name: dedicatedhdd
provisioner: kubernetes.io/azure-disk
parameters:
skuname: Standard_LRS

View File

@ -0,0 +1,21 @@
kind: Pod
apiVersion: v1
metadata:
name: pod-uses-shared-hdd-5g
labels:
name: storage
spec:
containers:
- image: nginx
name: az-c-01
command:
- /bin/sh
- -c
- while true; do echo $(date) >> /mnt/blobdisk/outfile; sleep 1; done
volumeMounts:
- name: blobdisk01
mountPath: /mnt/blobdisk
volumes:
- name: blobdisk01
persistentVolumeClaim:
claimName: pv-dd-shared-hdd-5g

View File

@ -0,0 +1,12 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pv-dd-shared-hdd-5g
annotations:
volume.beta.kubernetes.io/storage-class: sharedhdd
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi

View File

@ -0,0 +1,8 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
name: sharedhdd
provisioner: kubernetes.io/azure-disk
parameters:
skuname: Standard_LRS
kind: Shared

View File

@ -0,0 +1,21 @@
kind: Pod
apiVersion: v1
metadata:
name: pod-uses-shared-ssd-5g
labels:
name: storage
spec:
containers:
- image: nginx
name: az-c-01
command:
- /bin/sh
- -c
- while true; do echo $(date) >> /mnt/blobdisk/outfile; sleep 1; done
volumeMounts:
- name: blobdisk01
mountPath: /mnt/blobdisk
volumes:
- name: blobdisk01
persistentVolumeClaim:
claimName: pv-dd-shared-ssd-5g

View File

@ -0,0 +1,12 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pv-dd-shared-ssd-5g
annotations:
volume.beta.kubernetes.io/storage-class: sharedssd
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi

View File

@ -0,0 +1,8 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
name: sharedssd
provisioner: kubernetes.io/azure-disk
parameters:
skuname: Premium_LRS
kind: Shared

View File

@ -0,0 +1,21 @@
kind: Pod
apiVersion: v1
metadata:
name: pod-uses-managed-hdd-5g
labels:
name: storage
spec:
containers:
- image: nginx
name: az-c-01
command:
- /bin/sh
- -c
- while true; do echo $(date) >> /mnt/managed/outfile; sleep 1; done
volumeMounts:
- name: managed01
mountPath: /mnt/managed
volumes:
- name: managed01
persistentVolumeClaim:
claimName: dd-managed-hdd-5g

View File

@ -0,0 +1,12 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: dd-managed-hdd-5g
annotations:
volume.beta.kubernetes.io/storage-class: managedhdd
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi

View File

@ -0,0 +1,8 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
name: managedhdd
provisioner: kubernetes.io/azure-disk
parameters:
storageaccounttype: Standard_LRS
kind: Managed

View File

@ -0,0 +1,21 @@
kind: Pod
apiVersion: v1
metadata:
name: pod-uses-managed-ssd-5g
labels:
name: storage
spec:
containers:
- image: nginx
name: az-c-01
command:
- /bin/sh
- -c
- while true; do echo $(date) >> /mnt/managed/outfile; sleep 1; done
volumeMounts:
- name: managed01
mountPath: /mnt/managed
volumes:
- name: managed01
persistentVolumeClaim:
claimName: dd-managed-ssd-5g

View File

@ -0,0 +1,12 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: dd-managed-ssd-5g
annotations:
volume.beta.kubernetes.io/storage-class: managedssd
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi

View File

@ -0,0 +1,8 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
name: managedssd
provisioner: kubernetes.io/azure-disk
parameters:
storageaccounttype: Premium_LRS
kind: Managed