|
| 1 | +# Microsoft Azure Setup |
| 2 | + |
| 3 | +## Using Azure Managed PostgreSQL |
| 4 | + |
| 5 | +With the unified PostgreSQL configuration, connecting to an Azure managed PostgreSQL instance has become more straightforward. Here's how to set it up: |
| 6 | + |
| 7 | +1. **Create an Azure PostgreSQL server**: Create a PostgreSQL server using the Azure portal or the Azure CLI. |
| 8 | + |
| 9 | + ```bash |
| 10 | + # Example of creating an Azure PostgreSQL flexible server |
| 11 | + az postgres flexible-server create \ |
| 12 | + --resource-group myResourceGroup \ |
| 13 | + --name mypostgresserver \ |
| 14 | + --location westus \ |
| 15 | + --admin-user myusername \ |
| 16 | + --admin-password mypassword \ |
| 17 | + --sku-name Standard_B1ms |
| 18 | + ``` |
| 19 | + |
| 20 | +2. **Create a PostgreSQL database**: After creating the server, create a database for your EOAPI deployment. |
| 21 | + |
| 22 | + ```bash |
| 23 | + # Create a database on the Azure PostgreSQL server |
| 24 | + az postgres flexible-server db create \ |
| 25 | + --resource-group myResourceGroup \ |
| 26 | + --server-name mypostgresserver \ |
| 27 | + --database-name eoapi |
| 28 | + ``` |
| 29 | + |
| 30 | +3. **Configure firewall rules**: Ensure that the PostgreSQL server allows connections from your Kubernetes cluster's IP address. |
| 31 | + |
| 32 | + ```bash |
| 33 | + # Allow connections from your AKS cluster's outbound IP |
| 34 | + az postgres flexible-server firewall-rule create \ |
| 35 | + --resource-group myResourceGroup \ |
| 36 | + --server-name mypostgresserver \ |
| 37 | + --name AllowAKS \ |
| 38 | + --start-ip-address <AKS-outbound-IP> \ |
| 39 | + --end-ip-address <AKS-outbound-IP> |
| 40 | + ``` |
| 41 | + |
| 42 | +4. **Store PostgreSQL credentials in Azure Key Vault**: Create secrets in your Azure Key Vault to store the database connection information. |
| 43 | + |
| 44 | + ```bash |
| 45 | + # Create Key Vault secrets for PostgreSQL connection |
| 46 | + az keyvault secret set --vault-name your-keyvault-name --name db-host --value "mypostgresserver.postgres.database.azure.com" |
| 47 | + az keyvault secret set --vault-name your-keyvault-name --name db-port --value "5432" |
| 48 | + az keyvault secret set --vault-name your-keyvault-name --name db-name --value "eoapi" |
| 49 | + az keyvault secret set --vault-name your-keyvault-name --name db-username --value "myusername@mypostgresserver" |
| 50 | + az keyvault secret set --vault-name your-keyvault-name --name db-password --value "mypassword" |
| 51 | + ``` |
| 52 | + |
| 53 | +## Azure Configuration for eoapi-k8s |
| 54 | + |
| 55 | +When deploying on Azure, you'll need to configure several settings in your values.yaml file. Below are the configurations needed for proper integration with Azure services. |
| 56 | + |
| 57 | +### Common Azure Configuration |
| 58 | + |
| 59 | +First, configure the service account with Azure Workload Identity: |
| 60 | + |
| 61 | +```yaml |
| 62 | +# Service Account Configuration |
| 63 | +serviceAccount: |
| 64 | + create: true |
| 65 | + annotations: |
| 66 | + azure.workload.identity/client-id: "your-client-id" |
| 67 | + azure.workload.identity/tenant-id: "your-tenant-id" |
| 68 | +``` |
| 69 | +
|
| 70 | +### Unified PostgreSQL Configuration |
| 71 | +
|
| 72 | +Use the unified PostgreSQL configuration with the `external-secret` type to connect to your Azure managed PostgreSQL: |
| 73 | + |
| 74 | +```yaml |
| 75 | +# Configure PostgreSQL connection to use Azure managed PostgreSQL with secrets from Key Vault |
| 76 | +postgresql: |
| 77 | + # Use external-secret type to get credentials from a pre-existing secret |
| 78 | + type: "external-secret" |
| 79 | + |
| 80 | + # Basic connection information |
| 81 | + external: |
| 82 | + host: "mypostgresserver.postgres.database.azure.com" # Can be overridden by secret values |
| 83 | + port: "5432" # Can be overridden by secret values |
| 84 | + database: "eoapi" # Can be overridden by secret values |
| 85 | + |
| 86 | + # Reference to a secret that will be created by Azure Key Vault integration |
| 87 | + existingSecret: |
| 88 | + name: "azure-pg-credentials" |
| 89 | + keys: |
| 90 | + username: "username" # Secret key for the username |
| 91 | + password: "password" # Secret key for the password |
| 92 | + host: "host" # Secret key for the host (optional) |
| 93 | + port: "port" # Secret key for the port (optional) |
| 94 | + database: "database" # Secret key for the database name (optional) |
| 95 | +``` |
| 96 | + |
| 97 | +With this configuration, you're telling the PostgreSQL components to use an external PostgreSQL database and to get its connection details from a Kubernetes secret named `azure-pg-credentials`. This secret will be created using Azure Key Vault integration as described below. |
| 98 | + |
| 99 | +### Disable internal PostgreSQL cluster |
| 100 | + |
| 101 | +When using Azure managed PostgreSQL, you should disable the internal PostgreSQL cluster: |
| 102 | + |
| 103 | +```yaml |
| 104 | +postgrescluster: |
| 105 | + enabled: false |
| 106 | +``` |
| 107 | + |
| 108 | +### Azure Key Vault Integration |
| 109 | + |
| 110 | +To allow your Kubernetes pods to access PostgreSQL credentials stored in Azure Key Vault, create a SecretProviderClass: |
| 111 | + |
| 112 | +```yaml |
| 113 | +apiVersion: secrets-store.csi.x-k8s.io/v1 |
| 114 | +kind: SecretProviderClass |
| 115 | +metadata: |
| 116 | + name: azure-pg-secret-provider |
| 117 | +spec: |
| 118 | + provider: azure |
| 119 | + parameters: |
| 120 | + usePodIdentity: "false" |
| 121 | + clientID: "your-client-id" |
| 122 | + keyvaultName: "your-keyvault-name" |
| 123 | + tenantId: "your-tenant-id" |
| 124 | + objects: | |
| 125 | + array: |
| 126 | + - | |
| 127 | + objectName: db-host |
| 128 | + objectType: secret |
| 129 | + objectAlias: host |
| 130 | + - | |
| 131 | + objectName: db-port |
| 132 | + objectType: secret |
| 133 | + objectAlias: port |
| 134 | + - | |
| 135 | + objectName: db-name |
| 136 | + objectType: secret |
| 137 | + objectAlias: database |
| 138 | + - | |
| 139 | + objectName: db-username |
| 140 | + objectType: secret |
| 141 | + objectAlias: username |
| 142 | + - | |
| 143 | + objectName: db-password |
| 144 | + objectType: secret |
| 145 | + objectAlias: password |
| 146 | + secretObjects: |
| 147 | + - secretName: azure-pg-credentials |
| 148 | + type: Opaque |
| 149 | + data: |
| 150 | + - objectName: host |
| 151 | + key: host |
| 152 | + - objectName: port |
| 153 | + key: port |
| 154 | + - objectName: database |
| 155 | + key: database |
| 156 | + - objectName: username |
| 157 | + key: username |
| 158 | + - objectName: password |
| 159 | + key: password |
| 160 | +``` |
| 161 | + |
| 162 | +### Service Configuration |
| 163 | + |
| 164 | +For services that need to mount the Key Vault secrets, add the following configuration to each service (pgstacBootstrap, raster, stac, vector, multidim): |
| 165 | + |
| 166 | +```yaml |
| 167 | +# Define a common volume configuration for all services |
| 168 | +commonVolumeConfig: &commonVolumeConfig |
| 169 | + labels: |
| 170 | + azure.workload.identity/use: "true" |
| 171 | + extraVolumeMounts: |
| 172 | + - name: azure-keyvault-secrets |
| 173 | + mountPath: /mnt/secrets-store |
| 174 | + readOnly: true |
| 175 | + extraVolumes: |
| 176 | + - name: azure-keyvault-secrets |
| 177 | + csi: |
| 178 | + driver: secrets-store.csi.k8s.io |
| 179 | + readOnly: true |
| 180 | + volumeAttributes: |
| 181 | + secretProviderClass: azure-pg-secret-provider |
| 182 | +
|
| 183 | +# Apply the common volume configuration to each service |
| 184 | +pgstacBootstrap: |
| 185 | + enabled: true |
| 186 | + settings: |
| 187 | + <<: *commonVolumeConfig |
| 188 | +
|
| 189 | +raster: |
| 190 | + enabled: true |
| 191 | + settings: |
| 192 | + <<: *commonVolumeConfig |
| 193 | +
|
| 194 | +stac: |
| 195 | + enabled: true |
| 196 | + settings: |
| 197 | + <<: *commonVolumeConfig |
| 198 | +
|
| 199 | +vector: |
| 200 | + enabled: true |
| 201 | + settings: |
| 202 | + <<: *commonVolumeConfig |
| 203 | +
|
| 204 | +multidim: |
| 205 | + enabled: false # set to true if needed |
| 206 | + settings: |
| 207 | + <<: *commonVolumeConfig |
| 208 | +``` |
| 209 | + |
| 210 | +## Azure Managed Identity Setup |
| 211 | + |
| 212 | +To use Azure Managed Identity with your Kubernetes cluster: |
| 213 | + |
| 214 | +1. **Enable Workload Identity on your AKS cluster**: |
| 215 | + ```bash |
| 216 | + az aks update -g <resource-group> -n <cluster-name> --enable-workload-identity |
| 217 | + ``` |
| 218 | + |
| 219 | +2. **Create a Managed Identity**: |
| 220 | + ```bash |
| 221 | + az identity create -g <resource-group> -n eoapi-identity |
| 222 | + ``` |
| 223 | + |
| 224 | +3. **Configure Key Vault access**: |
| 225 | + ```bash |
| 226 | + # Get the client ID of the managed identity |
| 227 | + CLIENT_ID=$(az identity show -g <resource-group> -n eoapi-identity --query clientId -o tsv) |
| 228 | + |
| 229 | + # Grant access to Key Vault |
| 230 | + az keyvault set-policy -n <keyvault-name> --secret-permissions get list --spn $CLIENT_ID |
| 231 | + ``` |
| 232 | + |
| 233 | +4. **Create a federated identity credential** to connect the Kubernetes service account to the Azure managed identity: |
| 234 | + ```bash |
| 235 | + az identity federated-credential create \ |
| 236 | + --name eoapi-federated-credential \ |
| 237 | + --identity-name eoapi-identity \ |
| 238 | + --resource-group <resource-group> \ |
| 239 | + --issuer <aks-oidc-issuer> \ |
| 240 | + --subject system:serviceaccount:<namespace>:eoapi-sa |
| 241 | + ``` |
| 242 | + |
| 243 | +## Complete Example |
| 244 | + |
| 245 | +Here's a complete example configuration for connecting EOAPI to an Azure managed PostgreSQL database: |
| 246 | + |
| 247 | +```yaml |
| 248 | +# Service Account Configuration with Azure Workload Identity |
| 249 | +serviceAccount: |
| 250 | + create: true |
| 251 | + annotations: |
| 252 | + azure.workload.identity/client-id: "12345678-1234-1234-1234-123456789012" |
| 253 | + azure.workload.identity/tenant-id: "87654321-4321-4321-4321-210987654321" |
| 254 | +
|
| 255 | +# Unified PostgreSQL Configuration - using external-secret type |
| 256 | +postgresql: |
| 257 | + type: "external-secret" |
| 258 | + external: |
| 259 | + host: "mypostgresserver.postgres.database.azure.com" |
| 260 | + port: "5432" |
| 261 | + database: "eoapi" |
| 262 | + existingSecret: |
| 263 | + name: "azure-pg-credentials" |
| 264 | + keys: |
| 265 | + username: "username" |
| 266 | + password: "password" |
| 267 | + host: "host" |
| 268 | + port: "port" |
| 269 | + database: "database" |
| 270 | +
|
| 271 | +# Disable internal PostgreSQL cluster |
| 272 | +postgrescluster: |
| 273 | + enabled: false |
| 274 | +
|
| 275 | +# Define common volume configuration with Azure Key Vault integration |
| 276 | +commonVolumeConfig: &commonVolumeConfig |
| 277 | + labels: |
| 278 | + azure.workload.identity/use: "true" |
| 279 | + extraVolumeMounts: |
| 280 | + - name: azure-keyvault-secrets |
| 281 | + mountPath: /mnt/secrets-store |
| 282 | + readOnly: true |
| 283 | + extraVolumes: |
| 284 | + - name: azure-keyvault-secrets |
| 285 | + csi: |
| 286 | + driver: secrets-store.csi.k8s.io |
| 287 | + readOnly: true |
| 288 | + volumeAttributes: |
| 289 | + secretProviderClass: azure-pg-secret-provider |
| 290 | +
|
| 291 | +# Apply the common volume configuration to each service |
| 292 | +pgstacBootstrap: |
| 293 | + enabled: true |
| 294 | + settings: |
| 295 | + <<: *commonVolumeConfig |
| 296 | +
|
| 297 | +stac: |
| 298 | + enabled: true |
| 299 | + settings: |
| 300 | + <<: *commonVolumeConfig |
| 301 | +
|
| 302 | +raster: |
| 303 | + enabled: true |
| 304 | + settings: |
| 305 | + <<: *commonVolumeConfig |
| 306 | +
|
| 307 | +vector: |
| 308 | + enabled: true |
| 309 | + settings: |
| 310 | + <<: *commonVolumeConfig |
| 311 | +
|
| 312 | +multidim: |
| 313 | + enabled: false |
| 314 | + settings: |
| 315 | + <<: *commonVolumeConfig |
| 316 | +``` |
| 317 | + |
| 318 | +Make sure to create the SecretProviderClass as shown in the "Azure Key Vault Integration" section above before deploying EOAPI with this configuration. |
0 commit comments