Skip to content

Commit 2e2b040

Browse files
committed
add dynamic provisioning
1 parent 33d74f3 commit 2e2b040

File tree

3 files changed

+131
-60
lines changed

3 files changed

+131
-60
lines changed

deploy/example/mountstorage/README.md

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@ You can also use a different managed-identity for different persistent volumes (
1717

1818
- Create a storage account container, e.g.
1919
```bash
20-
resourcegroup="aks-fuseblob-mi"
20+
resourcegroup="blobfuse-mi"
2121
storageaccountname="myaksblob"
2222
az storage account create -g "$resourcegroup" -n "$storageaccountname" --access-tier Hot --sku Standard_LRS
2323
az storage container create -n mycontainer --account-name "$storageaccountname" --public-access off
2424
```
2525

26-
## option#1: grant kubelet identity access to storage account
26+
## Option#1: grant kubelet identity access to storage account
2727

2828
1. Give kubelet identity access to storage account
2929
```bash
3030
aksnprg="$(az aks list -g "$resourcegroup" --query "[?name == '$aksname'].nodeResourceGroup" -o tsv)"
31-
kloid="$(az identity list -g "$aksnprg" --query "[?name == 'aks-fuseblob-mi-agentpool'].principalId" -o tsv)"
31+
kloid="$(az identity list -g "$aksnprg" --query "[?name == 'blobfuse-mi-agentpool'].principalId" -o tsv)"
3232
said="$(az storage account list -g "$resourcegroup" --query "[?name == '$storageaccountname'].id" -o tsv)"
3333
az role assignment create --assignee-object-id "$kloid" --role "Storage Blob Data Owner" --scope "$said"
3434
```
3535

3636
1. Get the clientID of kubelet identity
3737
```bash
38-
az identity list -g "$resourcegroup" --query "[?name == 'aks-fuseblob-mi-agentpool'].clientId" -o tsv
38+
az identity list -g "$resourcegroup" --query "[?name == 'blobfuse-mi-agentpool'].clientId" -o tsv
3939
```
4040

41-
## option#2: grant a dedicated user-assigned managed identity access to storage account
41+
## Option#2: grant a dedicated user-assigned managed identity access to storage account
4242
You can use a dedicated user-assigned managed identity to mount the storage.
4343

4444
1. Create user-assigned managed identity and give access to storage account
@@ -89,7 +89,7 @@ You can use a dedicated user-assigned managed identity to mount the storage.
8989
volumeHandle: pv-blob1
9090
volumeAttributes:
9191
protocol: fuse
92-
resourceGroup: aks-fuseblob-mi
92+
resourceGroup: blobfuse-mi
9393
storageAccount: myaksblob
9494
containerName: mycontainer
9595
AzureStorageAuthType: MSI
@@ -117,33 +117,41 @@ You can use a dedicated user-assigned managed identity to mount the storage.
117117
kind: Deployment
118118
metadata:
119119
labels:
120-
app: nginx-app1
121-
name: nginx-app1
120+
app: nginx
121+
name: deployment-blob
122122
spec:
123123
replicas: 1
124124
selector:
125125
matchLabels:
126-
app: nginx-app1
126+
app: nginx
127127
template:
128128
metadata:
129129
labels:
130-
app: nginx-app1
130+
app: nginx
131+
name: deployment-blob
131132
spec:
133+
nodeSelector:
134+
"kubernetes.io/os": linux
132135
containers:
133-
- image: mcr.microsoft.com/oss/nginx/nginx:1.19.5
134-
name: webapp
135-
imagePullPolicy: Always
136-
resources: {}
137-
ports:
138-
- containerPort: 80
139-
volumeMounts:
140-
- name: pvc-blob1
141-
mountPath: /usr/share/nginx/html
142-
volumes:
143-
- name: pvc-blob1
144-
persistentVolumeClaim:
145-
claimName: pvc-blob1
146-
status: {}
136+
- name: deployment-blob
137+
image: mcr.microsoft.com/oss/nginx/nginx:1.17.3-alpine
138+
command:
139+
- "/bin/sh"
140+
- "-c"
141+
- while true; do echo $(date) >> /mnt/blob/outfile; sleep 1; done
142+
volumeMounts:
143+
- name: blob
144+
mountPath: "/mnt/blob"
145+
readOnly: false
146+
volumes:
147+
- name: blob
148+
persistentVolumeClaim:
149+
claimName: pvc-blob1
150+
strategy:
151+
rollingUpdate:
152+
maxSurge: 0
153+
maxUnavailable: 1
154+
type: RollingUpdate
147155
```
148156

149157
1. Apply the yaml files
@@ -154,12 +162,56 @@ You can use a dedicated user-assigned managed identity to mount the storage.
154162
kubectl get pv
155163
kubectl get pvc
156164
157-
# create deployment and service
165+
# create deployment
158166
kubectl apply -f deployment.yaml
159167
# check pod
160168
kubectl get pods
161169
```
162170

171+
# dynamic provisioning in an existing resource group
172+
173+
1. Grant cluster system assigned identity and kubelet identity `Contributor` role to resource group, if mount in an existing storage account, then should also grant identity to storage account
174+
175+
1. Grant kubelet identity `Storage Blob Data Owner` role to resource group to mount blob storage, if mount in an existing storage account, then should also grant identity to storage account
176+
177+
1. Create a storage class and give an existing resource group, CSI will create a new storage account when `storageAccount` is not provided.
178+
```yml
179+
apiVersion: storage.k8s.io/v1
180+
kind: StorageClass
181+
metadata:
182+
name: blob-fuse
183+
provisioner: blob.csi.azure.com
184+
parameters:
185+
skuName: Premium_LRS
186+
protocol: fuse
187+
resourceGroup: EXISTING_RESOURCE_GROUP_NAME
188+
storageAccount: EXISTING_STORAGE_ACCOUNT_NAME # optional, if use existing storage account
189+
containerName: EXISTING_CONTAINER_NAME # optional, if use existing container
190+
AzureStorageAuthType: MSI
191+
AzureStorageIdentityClientID: "xxxxx-xxxx-xxx-xxx-xxxxxxx"
192+
reclaimPolicy: Delete
193+
volumeBindingMode: Immediate
194+
allowVolumeExpansion: true
195+
mountOptions:
196+
- -o allow_other
197+
- --file-cache-timeout-in-seconds=120
198+
- --use-attr-cache=true
199+
- --cancel-list-on-mount-seconds=10 # prevent billing charges on mounting
200+
- -o attr_timeout=120
201+
- -o entry_timeout=120
202+
- -o negative_timeout=120
203+
- --log-level=LOG_WARNING # LOG_WARNING, LOG_INFO, LOG_DEBUG
204+
- --cache-size-mb=1000 # Default will be 80% of available memory, eviction will happen beyond that.
205+
```
206+
207+
1. Using dynamic provisioning
208+
```console
209+
# create pvc and deployment
210+
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/blob-csi-driver/master/deploy/example/deployment.yaml
211+
# check pod
212+
kubectl get pods
213+
```
214+
163215
# how to add another pv with a dedicated user-assigned identity?
164216

165217
1. Create another user-assigned managed identity and give access to storage account
@@ -208,7 +260,7 @@ You can use a dedicated user-assigned managed identity to mount the storage.
208260
volumeHandle: pv-blob2
209261
volumeAttributes:
210262
protocol: fuse
211-
resourceGroup: aks-fuseblob-mi
263+
resourceGroup: blobfuse-mi
212264
storageAccount: myaksblob
213265
containerName: mycontainer
214266
AzureStorageAuthType: MSI

deploy/example/mountstorage/deployment.yaml

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,38 @@ apiVersion: apps/v1
22
kind: Deployment
33
metadata:
44
labels:
5-
app: nginx-app1
6-
name: nginx-app1
5+
app: nginx
6+
name: deployment-blob
77
spec:
88
replicas: 1
99
selector:
1010
matchLabels:
11-
app: nginx-app1
11+
app: nginx
1212
template:
1313
metadata:
1414
labels:
15-
app: nginx-app1
15+
app: nginx
16+
name: deployment-blob
1617
spec:
18+
nodeSelector:
19+
"kubernetes.io/os": linux
1720
containers:
18-
- image: mcr.microsoft.com/oss/nginx/nginx:1.19.5
19-
name: webapp
20-
imagePullPolicy: Always
21-
resources: {}
22-
ports:
23-
- containerPort: 80
24-
volumeMounts:
25-
- name: pvc-blob1
26-
mountPath: /usr/share/nginx/html
27-
volumes:
28-
- name: pvc-blob1
29-
persistentVolumeClaim:
30-
claimName: pvc-blob1
31-
status: {}
32-
33-
---
34-
35-
apiVersion: v1
36-
kind: Service
37-
metadata:
38-
name: nginx-app1
39-
labels:
40-
run: nginx-app1
41-
spec:
42-
ports:
43-
- port: 80
44-
protocol: TCP
45-
selector:
46-
app: nginx-app1
47-
type: LoadBalancer
21+
- name: deployment-blob
22+
image: mcr.microsoft.com/oss/nginx/nginx:1.17.3-alpine
23+
command:
24+
- "/bin/sh"
25+
- "-c"
26+
- while true; do echo $(date) >> /mnt/blob/outfile; sleep 1; done
27+
volumeMounts:
28+
- name: blob
29+
mountPath: "/mnt/blob"
30+
readOnly: false
31+
volumes:
32+
- name: blob
33+
persistentVolumeClaim:
34+
claimName: pvc-blob1
35+
strategy:
36+
rollingUpdate:
37+
maxSurge: 0
38+
maxUnavailable: 1
39+
type: RollingUpdate
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
apiVersion: storage.k8s.io/v1
3+
kind: StorageClass
4+
metadata:
5+
name: blob-fuse
6+
provisioner: blob.csi.azure.com
7+
parameters:
8+
skuName: Premium_LRS
9+
protocol: fuse
10+
resourceGroup: EXISTING_RESOURCE_GROUP_NAME
11+
storageAccount: EXISTING_STORAGE_ACCOUNT_NAME # optional, if use existing storage account
12+
containerName: EXISTING_CONTAINER_NAME # optional, if use existing container
13+
AzureStorageAuthType: MSI
14+
AzureStorageIdentityClientID: "92926dfd-e61b-4730-85ab-5be73b374e82"
15+
reclaimPolicy: Delete
16+
volumeBindingMode: Immediate
17+
allowVolumeExpansion: true
18+
mountOptions:
19+
- -o allow_other
20+
- --file-cache-timeout-in-seconds=120
21+
- --use-attr-cache=true
22+
- --cancel-list-on-mount-seconds=10 # prevent billing charges on mounting
23+
- -o attr_timeout=120
24+
- -o entry_timeout=120
25+
- -o negative_timeout=120
26+
- --log-level=LOG_WARNING # LOG_WARNING, LOG_INFO, LOG_DEBUG
27+
- --cache-size-mb=1000 # Default will be 80% of available memory, eviction will happen beyond that.

0 commit comments

Comments
 (0)