|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * storage/persistent-storage/persistent-storage-csi.adoc |
| 4 | + |
| 5 | +[id="csi-example-deployment-{context}"] |
| 6 | += Example CSI deployment |
| 7 | + |
| 8 | +Since {product-title} does not ship with any CSI driver installed, this |
| 9 | +example shows how to deploy a community driver for OpenStack Cinder in |
| 10 | +{product-title}. |
| 11 | + |
| 12 | +.Procedure |
| 13 | + |
| 14 | +. Create a new project where the CSI components will run, and then create |
| 15 | +a new service account to run the components. An explicit node selector is |
| 16 | +used to run the Daemonset with the CSI driver also on master nodes. |
| 17 | ++ |
| 18 | +---- |
| 19 | +# oc adm new-project csi --node-selector="" |
| 20 | +Now using project "csi" on server "https://example.com:8443". |
| 21 | +
|
| 22 | +# oc create serviceaccount cinder-csi |
| 23 | +serviceaccount "cinder-csi" created |
| 24 | +
|
| 25 | +# oc adm policy add-scc-to-user privileged system:serviceaccount:csi:cinder-csi |
| 26 | +scc "privileged" added to: ["system:serviceaccount:csi:cinder-csi"] |
| 27 | +---- |
| 28 | + |
| 29 | +. Apply this YAML file to create the deployment with the external CSI |
| 30 | +attacher and provisioner and DaemonSet with the CSI driver. |
| 31 | ++ |
| 32 | +[source,yaml] |
| 33 | +---- |
| 34 | +# This YAML file contains all API objects that are necessary to run Cinder CSI |
| 35 | +# driver. |
| 36 | +# |
| 37 | +# In production, this needs to be in separate files, e.g. service account and |
| 38 | +# role and role binding needs to be created once. |
| 39 | +# |
| 40 | +# It server as an example how to use external attacher and external provisioner |
| 41 | +# images shipped with {product-title} with a community CSI driver. |
| 42 | +
|
| 43 | +kind: ClusterRole |
| 44 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 45 | +metadata: |
| 46 | + name: cinder-csi-role |
| 47 | +rules: |
| 48 | + - apiGroups: [""] |
| 49 | + resources: ["persistentvolumes"] |
| 50 | + verbs: ["create", "delete", "get", "list", "watch", "update", "patch"] |
| 51 | + - apiGroups: [""] |
| 52 | + resources: ["events"] |
| 53 | + verbs: ["create", "get", "list", "watch", "update", "patch"] |
| 54 | + - apiGroups: [""] |
| 55 | + resources: ["persistentvolumeclaims"] |
| 56 | + verbs: ["get", "list", "watch", "update", "patch"] |
| 57 | + - apiGroups: [""] |
| 58 | + resources: ["nodes"] |
| 59 | + verbs: ["get", "list", "watch", "update", "patch"] |
| 60 | + - apiGroups: ["storage.k8s.io"] |
| 61 | + resources: ["storageclasses"] |
| 62 | + verbs: ["get", "list", "watch"] |
| 63 | + - apiGroups: ["storage.k8s.io"] |
| 64 | + resources: ["volumeattachments"] |
| 65 | + verbs: ["get", "list", "watch", "update", "patch"] |
| 66 | + - apiGroups: [""] |
| 67 | + resources: ["configmaps"] |
| 68 | + verbs: ["get", "list", "watch", "create", "update", "patch"] |
| 69 | +
|
| 70 | +--- |
| 71 | +
|
| 72 | +kind: ClusterRoleBinding |
| 73 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 74 | +metadata: |
| 75 | + name: cinder-csi-role |
| 76 | +subjects: |
| 77 | + - kind: ServiceAccount |
| 78 | + name: cinder-csi |
| 79 | + namespace: csi |
| 80 | +roleRef: |
| 81 | + kind: ClusterRole |
| 82 | + name: cinder-csi-role |
| 83 | + apiGroup: rbac.authorization.k8s.io |
| 84 | +
|
| 85 | +--- |
| 86 | +apiVersion: v1 |
| 87 | +data: |
| 88 | + cloud.conf: W0dsb2JhbF0KYXV0aC11cmwgPSBodHRwczovL2V4YW1wbGUuY29tOjEzMDAwL3YyLjAvCnVzZXJuYW1lID0gYWxhZGRpbgpwYXNzd29yZCA9IG9wZW5zZXNhbWUKdGVuYW50LWlkID0gZTBmYTg1YjZhMDY0NDM5NTlkMmQzYjQ5NzE3NGJlZDYKcmVnaW9uID0gcmVnaW9uT25lCg== <1> |
| 89 | +kind: Secret |
| 90 | +metadata: |
| 91 | + creationTimestamp: null |
| 92 | + name: cloudconfig |
| 93 | +--- |
| 94 | +kind: Deployment |
| 95 | +apiVersion: apps/v1 |
| 96 | +metadata: |
| 97 | + name: cinder-csi-controller |
| 98 | +spec: |
| 99 | + replicas: 2 |
| 100 | + selector: |
| 101 | + matchLabels: |
| 102 | + app: cinder-csi-controllers |
| 103 | + template: |
| 104 | + metadata: |
| 105 | + labels: |
| 106 | + app: cinder-csi-controllers |
| 107 | + spec: |
| 108 | + serviceAccount: cinder-csi |
| 109 | + containers: |
| 110 | + - name: csi-attacher |
| 111 | + image: registry.redhat.io/openshift/csi-attacher:v4.0 |
| 112 | + args: |
| 113 | + - "--v=5" |
| 114 | + - "--csi-address=$(ADDRESS)" |
| 115 | + - "--leader-election" |
| 116 | + - "--leader-election-namespace=$(MY_NAMESPACE)" |
| 117 | + - "--leader-election-identity=$(MY_NAME)" |
| 118 | + env: |
| 119 | + - name: MY_NAME |
| 120 | + valueFrom: |
| 121 | + fieldRef: |
| 122 | + fieldPath: metadata.name |
| 123 | + - name: MY_NAMESPACE |
| 124 | + valueFrom: |
| 125 | + fieldRef: |
| 126 | + fieldPath: metadata.namespace |
| 127 | + - name: ADDRESS |
| 128 | + value: /csi/csi.sock |
| 129 | + volumeMounts: |
| 130 | + - name: socket-dir |
| 131 | + mountPath: /csi |
| 132 | + - name: csi-provisioner |
| 133 | + image: registry.redhat.io/openshift/csi-provisioner:v4.0 |
| 134 | + args: |
| 135 | + - "--v=5" |
| 136 | + - "--provisioner=csi-cinderplugin" |
| 137 | + - "--csi-address=$(ADDRESS)" |
| 138 | + env: |
| 139 | + - name: ADDRESS |
| 140 | + value: /csi/csi.sock |
| 141 | + volumeMounts: |
| 142 | + - name: socket-dir |
| 143 | + mountPath: /csi |
| 144 | + - name: cinder-driver |
| 145 | + image: k8scloudprovider/cinder-csi-plugin:v0.3.0 |
| 146 | + command: [ "/bin/cinder-csi-plugin" ] |
| 147 | + args: |
| 148 | + - "--nodeid=$(NODEID)" |
| 149 | + - "--endpoint=unix://$(ADDRESS)" |
| 150 | + - "--cloud-config=/etc/cloudconfig/cloud.conf" |
| 151 | + env: |
| 152 | + - name: NODEID |
| 153 | + valueFrom: |
| 154 | + fieldRef: |
| 155 | + fieldPath: spec.nodeName |
| 156 | + - name: ADDRESS |
| 157 | + value: /csi/csi.sock |
| 158 | + volumeMounts: |
| 159 | + - name: socket-dir |
| 160 | + mountPath: /csi |
| 161 | + - name: cloudconfig |
| 162 | + mountPath: /etc/cloudconfig |
| 163 | + volumes: |
| 164 | + - name: socket-dir |
| 165 | + emptyDir: |
| 166 | + - name: cloudconfig |
| 167 | + secret: |
| 168 | + secretName: cloudconfig |
| 169 | +
|
| 170 | +--- |
| 171 | +
|
| 172 | +kind: DaemonSet |
| 173 | +apiVersion: apps/v1 |
| 174 | +metadata: |
| 175 | + name: cinder-csi-ds |
| 176 | +spec: |
| 177 | + selector: |
| 178 | + matchLabels: |
| 179 | + app: cinder-csi-driver |
| 180 | + template: |
| 181 | + metadata: |
| 182 | + labels: |
| 183 | + app: cinder-csi-driver |
| 184 | + spec: |
| 185 | + <2> |
| 186 | + serviceAccount: cinder-csi |
| 187 | + containers: |
| 188 | + - name: csi-driver-registrar |
| 189 | + image: registry.redhat.io/openshift/csi-driver-registrar:v4.0 |
| 190 | + securityContext: |
| 191 | + privileged: true |
| 192 | + args: |
| 193 | + - "--v=5" |
| 194 | + - "--csi-address=$(ADDRESS)" |
| 195 | + env: |
| 196 | + - name: ADDRESS |
| 197 | + value: /csi/csi.sock |
| 198 | + - name: KUBE_NODE_NAME |
| 199 | + valueFrom: |
| 200 | + fieldRef: |
| 201 | + fieldPath: spec.nodeName |
| 202 | + volumeMounts: |
| 203 | + - name: socket-dir |
| 204 | + mountPath: /csi |
| 205 | + - name: cinder-driver |
| 206 | + securityContext: |
| 207 | + privileged: true |
| 208 | + capabilities: |
| 209 | + add: ["SYS_ADMIN"] |
| 210 | + allowPrivilegeEscalation: true |
| 211 | + image: k8scloudprovider/cinder-csi-plugin:v0.3.0 |
| 212 | + command: [ "/bin/cinder-csi-plugin" ] |
| 213 | + args: |
| 214 | + - "--nodeid=$(NODEID)" |
| 215 | + - "--endpoint=unix://$(ADDRESS)" |
| 216 | + - "--cloud-config=/etc/cloudconfig/cloud.conf" |
| 217 | + env: |
| 218 | + - name: NODEID |
| 219 | + valueFrom: |
| 220 | + fieldRef: |
| 221 | + fieldPath: spec.nodeName |
| 222 | + - name: ADDRESS |
| 223 | + value: /csi/csi.sock |
| 224 | + volumeMounts: |
| 225 | + - name: socket-dir |
| 226 | + mountPath: /csi |
| 227 | + - name: cloudconfig |
| 228 | + mountPath: /etc/cloudconfig |
| 229 | + - name: mountpoint-dir |
| 230 | + mountPath: /var/lib/origin/openshift.local.volumes/pods/ |
| 231 | + mountPropagation: "Bidirectional" |
| 232 | + - name: cloud-metadata |
| 233 | + mountPath: /var/lib/cloud/data/ |
| 234 | + - name: dev |
| 235 | + mountPath: /dev |
| 236 | + volumes: |
| 237 | + - name: cloud-metadata |
| 238 | + hostPath: |
| 239 | + path: /var/lib/cloud/data/ |
| 240 | + - name: socket-dir |
| 241 | + hostPath: |
| 242 | + path: /var/lib/kubelet/plugins/csi-cinderplugin |
| 243 | + type: DirectoryOrCreate |
| 244 | + - name: mountpoint-dir |
| 245 | + hostPath: |
| 246 | + path: /var/lib/origin/openshift.local.volumes/pods/ |
| 247 | + type: Directory |
| 248 | + - name: cloudconfig |
| 249 | + secret: |
| 250 | + secretName: cloudconfig |
| 251 | + - name: dev |
| 252 | + hostPath: |
| 253 | + path: /dev |
| 254 | +---- |
| 255 | +<1> Replace with `cloud.conf` for your OpenStack deployment. |
| 256 | +For example, the Secret can be generated using the `oc create secret |
| 257 | +generic cloudconfig --from-file cloud.conf --dry-run -o yaml`. |
| 258 | +<2> Optionally, add `nodeSelector` to the CSI driver pod template to |
| 259 | +configure the nodes on which the CSI driver starts. Only nodes matching |
| 260 | +the selector run pods that use volumes that are served by the CSI driver. |
| 261 | +Without `nodeSelector`, the driver runs on all nodes in the cluster. |
0 commit comments