Skip to content

Commit a0d205b

Browse files
authored
Update workload-identity-static-pv-mount.md
1 parent d84a738 commit a0d205b

File tree

1 file changed

+75
-40
lines changed

1 file changed

+75
-40
lines changed

docs/workload-identity-static-pv-mount.md

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,79 @@ az identity federated-credential create --name $FEDERATED_IDENTITY_NAME \
6565
--issuer $AKS_OIDC_ISSUER \
6666
--subject system:serviceaccount:${SERVICE_ACCOUNT_NAMESPACE}:${SERVICE_ACCOUNT_NAME}
6767
```
68+
## option#1: dynamic provisoning with storage class
69+
```
70+
cat <<EOF | kubectl apply -f -
71+
apiVersion: storage.k8s.io/v1
72+
kind: StorageClass
73+
metadata:
74+
name: blob-fuse
75+
provisioner: blob.csi.azure.com
76+
parameters:
77+
storageaccount: $ACCOUNT # required
78+
clientID: $USER_ASSIGNED_CLIENT_ID # required, $USER_ASSIGNED_CLIENT_ID is only for mount auth, make sure you CSI driver controller pod has `Contributor` role on the specified account
79+
resourcegroup: $STORAGE_RESOURCE_GROUP # optional, specified when the storage account is not under AKS node resource group(which is prefixed with "MC_")
80+
reclaimPolicy: Delete
81+
volumeBindingMode: Immediate
82+
allowVolumeExpansion: true
83+
mountOptions:
84+
- -o allow_other
85+
- --file-cache-timeout-in-seconds=120
86+
- --use-attr-cache=true
87+
- --cancel-list-on-mount-seconds=10 # prevent billing charges on mounting
88+
- -o attr_timeout=120
89+
- -o entry_timeout=120
90+
- -o negative_timeout=120
91+
- --log-level=LOG_WARNING # LOG_WARNING, LOG_INFO, LOG_DEBUG
92+
- --cache-size-mb=1000 # Default will be 80% of available memory, eviction will happen beyond that.
93+
---
94+
apiVersion: apps/v1
95+
kind: StatefulSet
96+
metadata:
97+
name: statefulset-blob
98+
namespace: ${SERVICE_ACCOUNT_NAMESPACE}
99+
labels:
100+
app: nginx
101+
spec:
102+
serviceName: statefulset-blob
103+
replicas: 1
104+
template:
105+
metadata:
106+
labels:
107+
app: nginx
108+
spec:
109+
serviceAccountName: $SERVICE_ACCOUNT_NAME #required, Pod lacks the necessary permission to mount the volume without this field
110+
nodeSelector:
111+
"kubernetes.io/os": linux
112+
containers:
113+
- name: statefulset-blob
114+
image: mcr.microsoft.com/mirror/docker/library/nginx:1.23
115+
command:
116+
- "/bin/bash"
117+
- "-c"
118+
- set -euo pipefail; while true; do echo $(date) >> /mnt/blob/outfile; sleep 1; done
119+
volumeMounts:
120+
- name: persistent-storage
121+
mountPath: /mnt/blob
122+
readOnly: false
123+
updateStrategy:
124+
type: RollingUpdate
125+
selector:
126+
matchLabels:
127+
app: nginx
128+
volumeClaimTemplates:
129+
- metadata:
130+
name: persistent-storage
131+
spec:
132+
storageClassName: blob-fuse
133+
accessModes: ["ReadWriteMany"]
134+
resources:
135+
requests:
136+
storage: 100Gi
137+
EOF
138+
```
68139

69-
## option#1: static provision with PV
140+
## option#2: static provision with PV
70141
```
71142
cat <<EOF | kubectl apply -f -
72143
apiVersion: v1
@@ -94,13 +165,12 @@ spec:
94165
containerName: $CONTAINER # required
95166
clientID: $USER_ASSIGNED_CLIENT_ID # required
96167
resourcegroup: $STORAGE_RESOURCE_GROUP # optional, specified when the storage account is not under AKS node resource group(which is prefixed with "MC_")
97-
# tenantID: $IDENTITY_TENANT #optional, only specified when workload identity and AKS cluster are in different tenant
98-
# subscriptionid: $SUBSCRIPTION #optional, only specified when workload identity and AKS cluster are in different subscription
99168
---
100169
kind: PersistentVolumeClaim
101170
apiVersion: v1
102171
metadata:
103172
name: pvc-blob
173+
namespace: ${SERVICE_ACCOUNT_NAMESPACE}
104174
spec:
105175
accessModes:
106176
- ReadWriteMany
@@ -116,6 +186,7 @@ metadata:
116186
labels:
117187
app: nginx
118188
name: deployment-blob
189+
namespace: ${SERVICE_ACCOUNT_NAMESPACE}
119190
spec:
120191
replicas: 1
121192
selector:
@@ -127,7 +198,7 @@ spec:
127198
app: nginx
128199
name: deployment-blob
129200
spec:
130-
serviceAccountName: $SERVICE_ACCOUNT_NAME #required, Pod has no permission to mount the volume without this field
201+
serviceAccountName: $SERVICE_ACCOUNT_NAME #required, Pod lacks the necessary permission to mount the volume without this field
131202
nodeSelector:
132203
"kubernetes.io/os": linux
133204
containers:
@@ -152,39 +223,3 @@ spec:
152223
type: RollingUpdate
153224
EOF
154225
```
155-
156-
## option#2: Pod with ephemeral inline volume
157-
```
158-
cat <<EOF | kubectl apply -f -
159-
kind: Pod
160-
apiVersion: v1
161-
metadata:
162-
name: nginx-blobfuse-inline-volume
163-
spec:
164-
serviceAccountName: $SERVICE_ACCOUNT_NAME #required, Pod does not use this service account has no permission to mount the volume
165-
nodeSelector:
166-
"kubernetes.io/os": linux
167-
containers:
168-
- image: mcr.microsoft.com/oss/nginx/nginx:1.19.5
169-
name: nginx-blobfuse
170-
command:
171-
- "/bin/bash"
172-
- "-c"
173-
- set -euo pipefail; while true; do echo $(date) >> /mnt/blobfuse/outfile; sleep 1; done
174-
volumeMounts:
175-
- name: persistent-storage
176-
mountPath: "/mnt/blobfuse"
177-
readOnly: false
178-
volumes:
179-
- name: persistent-storage
180-
csi:
181-
driver: blob.csi.azure.com
182-
volumeAttributes:
183-
storageaccount: $ACCOUNT # required
184-
containerName: $CONTAINER # required
185-
clientID: $USER_ASSIGNED_CLIENT_ID # required
186-
resourcegroup: $STORAGE_RESOURCE_GROUP # optional, specified when the storage account is not under AKS node resource group(which is prefixed with "MC_")
187-
# tenantID: $IDENTITY_TENANT # optional, only specified when workload identity and AKS cluster are in different tenant
188-
# subscriptionid: $SUBSCRIPTION # optional, only specified when workload identity and AKS cluster are in different subscription
189-
EOF
190-
```

0 commit comments

Comments
 (0)