|
| 1 | +--- |
| 2 | +title: Connect an Azure Elastic SAN Preview volume to an AKS cluster. |
| 3 | +description: Learn how to connect to an Azure Elastic SAN Preview volume an Azure Kubernetes Service cluster. |
| 4 | +author: roygara |
| 5 | +ms.service: storage |
| 6 | +ms.topic: how-to |
| 7 | +ms.date: 03/08/2023 |
| 8 | +ms.author: rogarana |
| 9 | +ms.subservice: elastic-san |
| 10 | +--- |
| 11 | + |
| 12 | +# Connect Azure Elastic SAN Preview volumes to an Azure Kubernetes Service cluster |
| 13 | + |
| 14 | +This article explains how to connect an Azure Elastic storage area network (SAN) Preview volume from an Azure Kubernetes Service (AKS) cluster. To make this connection, enable the [Kubernetes iSCSI CSI driver](https://github.com/kubernetes-csi/csi-driver-iscsi) on your cluster. With this driver, you can access volumes on your Elastic SAN by creating persistent volumes on your AKS cluster, and then attaching the Elastic SAN volumes to the persistent volumes. |
| 15 | + |
| 16 | +## About the driver |
| 17 | + |
| 18 | +The iSCSI CSI driver is an open source project that allows you to connect to a Kubernetes cluster over iSCSI. Since the driver is an open source project, Microsoft won't provide support from any issues stemming from the driver, itself. |
| 19 | + |
| 20 | +The Kubernetes iSCSI CSI driver is available on GitHub: |
| 21 | + |
| 22 | +- [Kubernetes iSCSI CSI driver repository](https://github.com/kubernetes-csi/csi-driver-iscsi) |
| 23 | +- [Readme](https://github.com/kubernetes-csi/csi-driver-iscsi/blob/master/README.md) |
| 24 | +- [Report iSCSI driver issues](https://github.com/kubernetes-csi/csi-driver-iscsi/issues) |
| 25 | + |
| 26 | +### Licensing |
| 27 | + |
| 28 | +The iSCSI CSI driver for Kubernetes is [licensed under the Apache 2.0 license](https://github.com/kubernetes-csi/csi-driver-iscsi/blob/master/LICENSE). |
| 29 | + |
| 30 | +## Prerequisites |
| 31 | + |
| 32 | +- Have an [Azure Elastic SAN](elastic-san-create.md) with volumes |
| 33 | +- Use either the [latest Azure CLI](/cli/azure/install-azure-cli) or install the [latest Azure PowerShell module](/powershell/azure/install-az-ps) |
| 34 | +- Meet the [compatibility requirements](https://github.com/kubernetes-csi/csi-driver-iscsi/blob/master/README.md#container-images--kubernetes-compatibility) for the iSCSI CSI driver |
| 35 | + |
| 36 | +## Limitations |
| 37 | + |
| 38 | +- Dynamic allocation isn't currently supported |
| 39 | +- Only `ReadWriteOnce` access mode is currently supported |
| 40 | + |
| 41 | +## Get started |
| 42 | + |
| 43 | +### Driver installation |
| 44 | + |
| 45 | +First, install the Kubernetes iSCSI CSI driver on your cluster. You have to perform a local install since a few code changes are required for the driver to connect to Elastic SAN volumes. |
| 46 | + |
| 47 | +First, clone the driver repo: |
| 48 | + |
| 49 | +``` |
| 50 | +git clone https://github.com/kubernetes-csi/csi-driver-iscsi.git |
| 51 | +``` |
| 52 | + |
| 53 | +Elastic SAN doesn't currently support dynamic discovery used in this driver. The following code changes in the driver are required to add volumes statically. |
| 54 | + |
| 55 | +Make the following modifications to pkg/lib/iscsi/iscsi/iscsi.go: |
| 56 | + |
| 57 | +First, add a new function for static discovery: |
| 58 | + |
| 59 | +``` |
| 60 | +// Add a new function to make static discovery |
| 61 | +func (c *Connector) discoverTargetStatically(targetIqn string, iFace string, portal string) error { |
| 62 | + err := CreateDBEntry(targetIqn, portal, iFace, c.DiscoverySecrets, c.SessionSecrets) |
| 63 | + if err != nil { |
| 64 | + debug.Printf("Error creating db entry: %s\n", err.Error()) |
| 65 | + return err |
| 66 | + } |
| 67 | + return nil |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +Then, make the following change so that you can use the function you created: |
| 72 | + |
| 73 | +Replace: |
| 74 | +``` |
| 75 | +if err := c.discoverTarget(targetIqn, iFace, portal); err != nil |
| 76 | +``` |
| 77 | +with: |
| 78 | +``` |
| 79 | +if err := c.discoverTargetStatically |
| 80 | +``` |
| 81 | + |
| 82 | +After the modifications, run the remaining install scripts: |
| 83 | + |
| 84 | +``` |
| 85 | +cd csi-driver-iscsi |
| 86 | +
|
| 87 | +./deploy/install-driver.sh master local |
| 88 | +``` |
| 89 | + |
| 90 | +After deployment, check the pods status to verify that the driver installed. |
| 91 | + |
| 92 | +```bash |
| 93 | +kubectl -n kube-system get pod -o wide -l app=csi-iscsi-node |
| 94 | +``` |
| 95 | + |
| 96 | +### Volume information |
| 97 | + |
| 98 | +To connect an Elastic SAN volume to an AKS cluster, you need the volume's StorageTargetIQN, StorageTargetPortalHostName, and StorageTargetPortalPort. |
| 99 | + |
| 100 | +You may get them with the following Azure PowerShell command: |
| 101 | + |
| 102 | +```azurepowershell |
| 103 | +Get-AzElasticSanVolume -ResourceGroupName $resourceGroupName -ElasticSanName $sanName -VolumeGroupName $searchedVolumeGroup -Name $searchedVolume |
| 104 | +``` |
| 105 | + |
| 106 | +You may also get them with the following Azure CLI command: |
| 107 | + |
| 108 | +```azurecli |
| 109 | +az elastic-san volume show --elastic-san-name --name --resource-group --volume-group-name |
| 110 | +``` |
| 111 | + |
| 112 | +### Cluster configuration |
| 113 | + |
| 114 | +Once you've retrieved your volume's information, you need to create a few yml files for your new resources on your AKS cluster. |
| 115 | + |
| 116 | +### Storageclass |
| 117 | + |
| 118 | +Use the following example to create a storageclass.yml file. This file defines your persistent volume's storageclass. |
| 119 | + |
| 120 | +```yml |
| 121 | +apiVersion: storage.k8s.io/v1 |
| 122 | +kind: StorageClass |
| 123 | +metadata: |
| 124 | + name: sanVolume |
| 125 | +provisioner: manual |
| 126 | +``` |
| 127 | +
|
| 128 | +### Persistent volume |
| 129 | +
|
| 130 | +After you've created the storage class, create a *pv.yml* file. This file defines your [persistent volume](../../aks/concepts-storage.md#persistent-volumes). In the following example, replace `yourTargetPortal`, `yourTargetPortalPort`, and `yourIQN` with the values you collected earlier, then use the example to create a *pv.yml* file. If you need more than 1 gibibyte of storage and have it available, replace `1Gi` with the amount of storage you require. |
| 131 | + |
| 132 | +```yml |
| 133 | +--- |
| 134 | +apiVersion: v1 |
| 135 | +kind: PersistentVolume |
| 136 | +metadata: |
| 137 | + name: iscsiplugin-pv |
| 138 | + labels: |
| 139 | + name: data-iscsiplugin |
| 140 | +spec: |
| 141 | + storageClassName: sanVolume |
| 142 | + accessModes: |
| 143 | + - ReadWriteOnce |
| 144 | + capacity: |
| 145 | + storage: 1Gi |
| 146 | + csi: |
| 147 | + driver: iscsi.csi.k8s.io |
| 148 | + volumeHandle: iscsi-data-id |
| 149 | + volumeAttributes: |
| 150 | + targetPortal: "yourTargetPortal:yourTargetPortalPort" |
| 151 | + portals: "[]" |
| 152 | + iqn: "yourIQN" |
| 153 | + lun: "0" |
| 154 | + iscsiInterface: "default" |
| 155 | + discoveryCHAPAuth: "false" |
| 156 | + sessionCHAPAuth: "false" |
| 157 | +``` |
| 158 | + |
| 159 | +After creating the *pv.yml* file, create a persistent volume with the following command: |
| 160 | + |
| 161 | +```bash |
| 162 | +kubectl apply -f pathtoyourfile/pv.yaml |
| 163 | +``` |
| 164 | + |
| 165 | +### Persistent volume claim |
| 166 | + |
| 167 | +Next, create a [persistent volume claim](../../aks/concepts-storage.md#persistent-volume-claims). Use the storage class we defined earlier with the persistent volume we defined. The following is an example of what your pvc.yml file might look like: |
| 168 | + |
| 169 | +```yml |
| 170 | +apiVersion: v1 |
| 171 | +kind: PersistentVolumeClaim |
| 172 | +metadata: |
| 173 | + name: iscsiplugin-pvc |
| 174 | +spec: |
| 175 | + accessModes: |
| 176 | + - ReadWriteOnce |
| 177 | + resources: |
| 178 | + requests: |
| 179 | + storage: 1Gi |
| 180 | + storageClassName: sanVolume |
| 181 | + selector: |
| 182 | + matchExpressions: |
| 183 | + - key: name |
| 184 | + operator: In |
| 185 | + values: ["data-iscsiplugin"] |
| 186 | +``` |
| 187 | + |
| 188 | +After creating the *pvc.yml* file, create a persistent volume claim. |
| 189 | + |
| 190 | +```bash |
| 191 | +kubectl apply -f pathtoyourfile/pvc.yaml |
| 192 | +``` |
| 193 | + |
| 194 | +To verify your PersistentVolumeClaim is created and bound to the PersistentVolume, run the following command: |
| 195 | + |
| 196 | +```bash |
| 197 | +kubectl get pvc pathtoyourfile |
| 198 | +``` |
| 199 | + |
| 200 | + |
| 201 | +Finally, create a [pod manifest](../../aks/concepts-clusters-workloads.md#pods). The following is an example of what your *pod.yml* file might look like. You can use it to make your own pod manifest, replace the values for `name`, `image`, and `mountPath` with your own: |
| 202 | + |
| 203 | +```yml |
| 204 | +apiVersion: v1 |
| 205 | +kind: Pod |
| 206 | +metadata: |
| 207 | + name: nginx |
| 208 | +spec: |
| 209 | + containers: |
| 210 | + - image: maersk/nginx |
| 211 | + imagePullPolicy: Always |
| 212 | + name: nginx |
| 213 | + ports: |
| 214 | + - containerPort: 80 |
| 215 | + protocol: TCP |
| 216 | + volumeMounts: |
| 217 | + - mountPath: /var/www |
| 218 | + name: iscsi-volume |
| 219 | + volumes: |
| 220 | + - name: iscsi-volume |
| 221 | + persistentVolumeClaim: |
| 222 | + claimName: iscsiplugin-pvc |
| 223 | +``` |
| 224 | + |
| 225 | +After creating the *pod.yml* file, create a pod. |
| 226 | + |
| 227 | +```bash |
| 228 | +kubectl apply -f pathtoyourfile/pod.yaml |
| 229 | +``` |
| 230 | + |
| 231 | +To verify your Pod was created, run the following command: |
| 232 | + |
| 233 | +```bash |
| 234 | +kubectl get pods |
| 235 | +``` |
| 236 | + |
| 237 | +You've now successfully connected an Elastic SAN volume to your AKS cluster. |
| 238 | + |
| 239 | +## Next steps |
| 240 | + |
| 241 | +[Plan for deploying an Elastic SAN Preview](elastic-san-planning.md) |
0 commit comments