Provisioning Azure Database for MySQL - Single Server from AKS

Published Sep 03 2021 02:17 PM 10.3K Views
Microsoft

To gain the benefits of using a MySQL database in a Kubernetes application, a common strategy is to provision the database in a container running in a pod. In doing so, the database will use the cluster resources. Accessing the database from other pods in the same AKS cluster running client apps is possible via Kubernetes networking. However, if for some reason cluster resources become unavailable, both the application and the database will be unavailable, as both rely on cluster health.

 

Important: Provisioning from Azure Kubernetes Service (AKS) using Azure Service Operator (ASO) is currently tested with the v1 alpha version, which only supports Azure Database for MySQL - Single Server. The v2 beta version will offer support for Azure Database for MySQL - Flexible Server. For production environments, consider waiting to use the v2 beta release.

 

To address the issue of cluster resources being shared between the application and database, you can substitute the local database in AKS with Azure Database for MySQL, which separates the database from the AKS cluster. Thus, cluster resources will remain focused on delivering infrastructure required to run the app and database availability will not be impacted by AKS availability. By making this change, the architecture will be updated as shown in the following diagram.

 

AKS blog.png

 

You can provision Azure Database for MySQL programmatically using Terraform, or you can integrate it with the Kubernetes services. This post provides the steps for provisioning from Kubernetes using ASO, which allows dynamic deployment of Azure services directly from AKS. This makes the resources accessible from pods within the AKS cluster.

 

ASO runs as a collection of pods (controller and manager pods) in your AKS cluster and requires a certificate and a Service Principal (SP) to create resources in the subscription. In the following steps, you'll use Helm to add ASO. Helm is an open-source packaging tool that helps you install and manage the lifecycle of Kubernetes applications. Similar to Linux package managers like APT and Yum, Helm manages Kubernetes charts, which are packages of pre-configured Kubernetes resources.

 

Deployment of Azure MySQL Database is performed via a YAML file that serves as the basis for Kubernetes deployment and configuration of the pods. In the YAML file, the description of the service is provided, and the service deployment is performed via kubectl. kubectl is the Kubernetes command-line client, used to manage a Kubernetes cluster and is already installed if you use Azure Cloud Shell.

 

To provision, perform the following steps.

 

  1.  Open the Cloud Shell, and then connect to your AKS cluster by running the following command:
    az aks get-credentials --resource-group RGNAME --name CLUSTERNAME​
  2.  Add cert-manager to the cluster by running the following command:
    kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.5.3/cert-manager.yaml​
  3.  Create a Helm repository and charts for ASO by running the following command:
    helm repo add aso https://raw.githubusercontent.com/Azure/azure-service-operator/master/charts​
  4.  Create an Azure service principal by running the following command:
    az ad sp create-for-rbac --name "azure-service-operator" --role contributor --scopes /subscriptions/<AZURE_SUBSCRIPTION_ID>​
    Output:
    {
      "appId": "2c0e1d61-1ac7-4710-9f60-d4844c47dd21",
      "displayName": "azure-service-operator",
      "name": "2c0e1d61-1ac7-4710-9f60-d4844c47dd21",
      "password": "iBW-RKtsq.ScrVdUp2_4SSKgI0P_eMFbh-",
      "tenant": "72f988bf-86f1-41af-91ab-2d7cd011db47"
    }
  5.  Install ASO on your Kubernetes cluster by running the following command:
    helm upgrade --install aso aso/azure-service-operator \
    --create-namespace \
    --namespace=azureoperator-system \
    --set azureSubscriptionID=<AZURE_SUBSCRIPTION_ID> \
    --set azureTenantID=<TENANT> \
    --set azureClientID=<APPID> \
    --set azureClientSecret=<PASSWORD>
  6.  Verify that the ASO is operating properly by running the following command:
    kubectl get pods -n azureoperator-system​
    The results will appear as shown in the following diagram.

    image3.PNG

  7. Create a YAML file named myfile.yml by running the following command:
    code myfile.yml​
  8. In the newly created myfile.yml, insert the desired configuration for the MySQL server and databases, along with the server firewall rule to allow access to the server after deployment. Sample contents of the file myfile.yml are shown in the following diagram. The content sample of YAML file can also be accessed at this repository. Save the YAML configuration file.
    # Azure Database for MySQL deployment
    
    apiVersion: azure.microsoft.com/v1alpha2
    kind: MySQLServer
    metadata:
         name: mysqlappdbserver
         labels: # Provide tags to add to the KeyVault as labels
         tag1: value1
         tag2: value2
    spec:
         location: eastus
         resourceGroup: MyResourceGroup
         serverVersion: "5.7" # could also be 8.0
         sslEnforcement: Enabled
         createMode: Default # Possible values include: Default, Replica, PointInTimeRestore (not implemented), GeoRestore (not implemented)
         # Optional admin secret name. If the admin secret is specified the `username` and `password` fields of the secret will be used to set
         # the administrator username and password. If adminSecret is not provided, ASO will generate an administrator account
         # and password.
         # adminSecret: my-admin-secret
         sku:
              name: GP_Gen5_4
              tier: GeneralPurpose # possible values - 'Basic', 'GeneralPurpose', 'MemoryOptimized'
              family: Gen5
              size: "51200"
              capacity: 4
              # Optional Backup Retention Config
              # storageProfile:
              # backupRetentionDays: 10
              # geoRedundantBackup: Enabled # Disabled or Enabled
              # storageMB: 5120 # max storage - minimum of 5120 MB and additional increments of 1024 MB up to maximum of 16777216 MB
              # storageAutogrow: Enabled # Disabled or Enabled
    ---
    apiVersion: azure.microsoft.com/v1alpha1
    kind: MySQLFirewallRule
    metadata:
         name: mysqlfirewallrule-azureservices
    spec:
         resourceGroup: MyResourceGroup
         server: mysqlappdbserver
         startIpAddress: 0.0.0.0
         endIpAddress: 0.0.0.0
    ---
    apiVersion: azure.microsoft.com/v1alpha1
    kind: MySQLDatabase
    metadata:
         name: mydatabasename
    spec:
         resourceGroup: MyResourceGroup
         server: mysqlappdbserver
  9.  Deploy MySQL server by running the following command:
    kubectl appy -f myfile.yml​
  10.  Check the deployment status by running the following command:
    kubectl get MySqlServer​

    The results will appear as shown in the following diagram.
    image4.PNG
    The server is now accessible via the Azure portal as well.

Note: You can explicitly provide the username and password in the YAML config file, or you can use them as environmental variables to connect your application to the server. The server name, username, and password are stored as keys in the secret generated by Kubernetes. To view the encoded keys run the following command:

 

 

 

 

 

 

 

kubectl describe secrets mysqlserver-mysqlappdbserver

 

 

 

 

 

 

 

A similar output will appear:

image5.PNG

You can reference the secret inside the YAML file for a pod that configures an app that needs to connect to the service in a deployment. The following example retrieves the values of the fullyQualifiedServerName, fullyQualifiedUsername, and password keys, and makes them available as environment variables inside a pod.

 

 

 

 

 

 

 

apiVersion: apps/v1
kind: Deployment
metadata:
    name: mysqlapp
spec:
    replicas: 4
    selector: 
 …
    template: 
	 …
    	spec: 
		…
         containers: 
		…
         env:
	   - name: MYSQL_USER
		valueFrom:
		  secretKeyRef:
			name: mysqlserver-mysqlappdbserver
			key:	fullyQualifiedUsername
         - name: MYSQL_PASSWORD
		valueFrom:
		  secretKeyRef:
			name: mysqlserver-mysqlappdbserver
			key:	password
         - name: MYSQL_SERVICE_HOST
		valueFrom:
		  secretKeyRef:
			name: mysqlserver-mysqlappdbserver
			key:	fullyQualifiedServerName
         - name: MYSQL_SERVICE_PORT
		value: '3306'

 

 

 

 

 

 

 

The application will retrieve environmental variables above and use them to construct a connector to the database server. The advantage of this approach is that connection credentials are not exposed to the app, reducing the chances of accidental disclosure.

 

Supportability note: This approach is also supported for Azure Database for PostgreSQL, Azure SQL Database, and Azure Cosmos DB. For more details and YAML code examples, please check the following repository. A list of ASO supported resources can be found here.

%3CLINGO-SUB%20id%3D%22lingo-sub-2695317%22%20slang%3D%22en-US%22%3EProvisioning%20Azure%20Database%20for%20MySQL%20-%20Single%20Server%20from%20AKS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2695317%22%20slang%3D%22en-US%22%3E%3CP%3ETo%20gain%20the%20benefits%20of%20using%20a%20MySQL%20database%20in%20a%20Kubernetes%20application%2C%20a%20common%20strategy%20is%20to%20provision%20the%20database%20in%20a%20container%20running%20in%20a%20pod.%20In%20doing%20so%2C%20the%20database%20will%20use%20the%20cluster%20resources.%20Accessing%20the%20database%20from%20other%20pods%20in%20the%20same%20AKS%20cluster%20running%20client%20apps%20is%20possible%20via%20Kubernetes%20networking.%20However%2C%20if%20for%20some%20reason%20cluster%20resources%20become%20unavailable%2C%20both%20the%20application%20and%20the%20database%20will%20be%20unavailable%2C%20as%20both%20rely%20on%20cluster%20health.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%23000000%22%3E%3CSTRONG%3EImportant%3C%2FSTRONG%3E%3C%2FFONT%3E%3A%20Provisioning%20from%20Azure%20Kubernetes%20Service%20(AKS)%20using%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fcloudblogs.microsoft.com%2Fopensource%2F2020%2F06%2F25%2Fannouncing-azure-service-operator-kubernetes%2F%23%3A~%3Atext%3DAzure%2520Service%2520Operator%2520allows%2520users%2520to%2520dynamically%2520provision%2Canywhere%2520Kubernetes%2520runs%25E2%2580%2595public%252C%2520private%252C%2520hybrid%252C%2520multi-cloud%252C%2520and%2520on-premises.%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Service%20Operator%3C%2FA%3E%3C%2FSPAN%3E%20(ASO)%20is%20currently%20tested%20with%20the%20v1%20alpha%20version%2C%20which%20only%20supports%26nbsp%3B%3CSTRONG%3EAzure%20Database%20for%20MySQL%20-%20Single%20Server%3C%2FSTRONG%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E.%20The%20v2%20beta%20version%20will%20offer%20support%20for%20Azure%20Database%20for%20MySQL%20-%20Flexible%20Server.%20For%20production%20environments%2C%20consider%20waiting%20to%20use%20the%20v2%20beta%20release.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20address%20the%20issue%20of%20cluster%20resources%20being%20shared%26nbsp%3B%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3Ebetween%20the%20application%20and%20database%2C%20you%20can%20substitute%20the%20local%20database%20in%20AKS%20with%20Azure%20Database%20for%20MySQL%2C%20which%20separates%20the%20database%20from%20the%20AKS%20cluster.%20Thus%2C%20cluster%20resources%20will%20remain%20focused%20on%20delivering%20infrastructure%20required%20to%20run%20the%20app%20and%20database%20availability%20will%20not%20be%20impacted%20by%20AKS%20availability.%20By%20making%20this%20change%2C%20the%20architecture%20will%20be%20updated%20as%20shown%20in%20the%20following%20diagram.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AKS%20blog.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F306825i379E0921B35CE965%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22AKS%20blog.png%22%20alt%3D%22AKS%20blog.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20provision%20Azure%20Database%20for%20MySQL%20programmatically%20using%20%3CA%20href%3D%22https%3A%2F%2Fwww.terraform.io%2Fdocs%2Fcloud%2Fintegrations%2Fkubernetes%2Findex.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ETerraform%3C%2FA%3E%2C%20or%20you%20can%20integrate%20it%20with%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Faks%2Fintro-kubernetes%23%3A~%3Atext%3D%2520Azure%2520Kubernetes%2520Service%2520%25201%2520Access%252C%2520security%252C%2Can%2520existing%2520virtual%2520network.%2520%2520...%2520More%2520%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EKubernetes%20services%3C%2FA%3E.%20This%20post%20provides%20the%20steps%20for%20provisioning%20from%20Kubernetes%20using%20ASO%2C%20which%20allows%20dynamic%20deployment%20of%20Azure%20services%20directly%20from%20AKS.%20This%20makes%20the%20resources%20accessible%20from%20pods%20within%20the%20AKS%20cluster.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EASO%20runs%20as%20a%20collection%20of%20pods%20(controller%20and%20manager%20pods)%20in%20your%20AKS%20cluster%20and%20requires%20a%20certificate%20and%20a%20Service%20Principal%20(SP)%20to%20create%20resources%20in%20the%20subscription.%20In%20the%20following%20steps%2C%20you'll%20use%20Helm%20to%20add%20ASO.%20%3CA%20title%3D%22Helm%22%20href%3D%22https%3A%2F%2Fhelm.sh%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EHelm%3C%2FA%3E%20is%20an%20open-source%20packaging%20tool%20that%20helps%20you%20install%20and%20manage%20the%20lifecycle%20of%20Kubernetes%20applications.%20Similar%20to%20Linux%20package%20managers%20like%26nbsp%3B%3CEM%3EAPT%3C%2FEM%3E%26nbsp%3Band%26nbsp%3B%3CEM%3EYum%3C%2FEM%3E%2C%20Helm%20manages%20Kubernetes%20charts%2C%20which%20are%20packages%20of%20pre-configured%20Kubernetes%20resources.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDeployment%20of%20Azure%20MySQL%20Database%20is%20performed%20via%20a%20YAML%20file%20that%20serves%20as%20the%20basis%20for%20Kubernetes%20deployment%20and%20configuration%20of%20the%20pods.%20In%20the%20YAML%20file%2C%20the%20description%20of%20the%20service%20is%20provided%2C%20and%20the%20service%20deployment%20is%20performed%20via%20%3CA%20href%3D%22https%3A%2F%2Fkubernetes.io%2Fdocs%2Freference%2Fkubectl%2Fkubectl%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E%3CEM%3Ekubectl%3C%2FEM%3E%3C%2FA%3E.%20%3CEM%3Ekubectl%3C%2FEM%3E%26nbsp%3Bis%20the%20Kubernetes%20command-line%20client%2C%20used%20to%20manage%20a%20Kubernetes%20cluster%20and%20is%20already%20installed%20if%20you%20use%20Azure%20Cloud%20Shell.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20provision%2C%20perform%20the%20following%20steps.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%26nbsp%3BOpen%20the%20Cloud%20Shell%2C%20and%20then%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Faks%2Fkubernetes-walkthrough%23connect-to-the-cluster%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Econnect%20to%20your%20AKS%20cluster%3C%2FA%3E%20by%20running%20the%20following%20command%3A%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Eaz%20aks%20get-credentials%20--resource-group%20RGNAME%20--name%20CLUSTERNAME%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BAdd%20cert-manager%20to%20the%20cluster%20by%20running%20the%20following%20command%3A%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Ekubectl%20apply%20-f%20https%3A%2F%2Fgithub.com%2Fjetstack%2Fcert-manager%2Freleases%2Fdownload%2Fv1.5.3%2Fcert-manager.yaml%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BCreate%20a%20Helm%20repository%20and%20charts%20for%20ASO%20by%20running%20the%20following%20command%3A%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Ehelm%20repo%20add%20aso%20https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-service-operator%2Fmaster%2Fcharts%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BCreate%20an%20Azure%20service%20principal%20by%20running%20the%20following%20command%3A%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Eaz%20ad%20sp%20create-for-rbac%20--name%20%22azure-service-operator%22%20--role%20contributor%20--scopes%20%2Fsubscriptions%2F%3CAZURE_SUBSCRIPTION_ID%3E%E2%80%8B%3C%2FAZURE_SUBSCRIPTION_ID%3E%3C%2FCODE%3E%3C%2FPRE%3EOutput%3A%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3E%7B%0A%20%20%22appId%22%3A%20%222c0e1d61-1ac7-4710-9f60-d4844c47dd21%22%2C%0A%20%20%22displayName%22%3A%20%22azure-service-operator%22%2C%0A%20%20%22name%22%3A%20%222c0e1d61-1ac7-4710-9f60-d4844c47dd21%22%2C%0A%20%20%22password%22%3A%20%22iBW-RKtsq.ScrVdUp2_4SSKgI0P_eMFbh-%22%2C%0A%20%20%22tenant%22%3A%20%2272f988bf-86f1-41af-91ab-2d7cd011db47%22%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BInstall%20ASO%20on%20your%20Kubernetes%20cluster%20by%20running%20the%20following%20command%3A%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Ehelm%20upgrade%20--install%20aso%20aso%2Fazure-service-operator%20%5C%0A--create-namespace%20%5C%0A--namespace%3Dazureoperator-system%20%5C%0A--set%20azureSubscriptionID%3D%3CAZURE_SUBSCRIPTION_ID%3E%20%5C%0A--set%20azureTenantID%3D%3CTENANT%3E%20%5C%0A--set%20azureClientID%3D%3CAPPID%3E%20%5C%0A--set%20azureClientSecret%3D%3CPASSWORD%3E%3C%2FPASSWORD%3E%3C%2FAPPID%3E%3C%2FTENANT%3E%3C%2FAZURE_SUBSCRIPTION_ID%3E%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BVerify%20that%20the%20ASO%20is%20operating%20properly%20by%20running%20the%20following%20command%3A%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Ekubectl%20get%20pods%20-n%20azureoperator-system%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3EThe%20results%20will%20appear%20as%20shown%20in%20the%20following%20diagram.%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image3.PNG%22%20style%3D%22width%3A%20745px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F306425iDB396845841002E5%2Fimage-dimensions%2F745x60%3Fv%3Dv2%22%20width%3D%22745%22%20height%3D%2260%22%20role%3D%22button%22%20title%3D%22image3.PNG%22%20alt%3D%22image3.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3ECreate%20a%20YAML%20file%20named%20%3CSTRONG%3Emyfile.yml%3C%2FSTRONG%3E%20by%20running%20the%20following%20command%3A%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Ecode%20myfile.yml%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3EIn%20the%20newly%20created%20%3CSTRONG%20style%3D%22font-family%3A%20inherit%3B%22%3Emyfile.yml%3C%2FSTRONG%3E%2C%20insert%20the%20desired%20configuration%20for%20the%20MySQL%20server%20and%20databases%2C%20along%20with%20the%20server%20firewall%20rule%20to%20allow%20access%20to%20the%20server%20after%20deployment.%20%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3ESample%20contents%20of%20the%20file%20%3C%2FSPAN%3E%3CSTRONG%20style%3D%22font-family%3A%20inherit%3B%22%3Emyfile.yml%3C%2FSTRONG%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E%20are%20shown%20in%20the%20following%20diagram.%20The%20content%20sample%20of%20YAML%20file%20can%20also%20be%20accessed%20at%26nbsp%3B%3C%2FSPAN%3E%3CA%20style%3D%22font-family%3A%20inherit%3B%20background-color%3A%20%23ffffff%3B%22%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-service-operator%2Fblob%2Fmaster%2Fconfig%2Fsamples%2Fazure_v1alpha1_mysql_everything.yaml%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ethis%20repository%3C%2FA%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E.%20Save%20the%20YAML%20configuration%20file.%3C%2FSPAN%3E%3C%2FSPAN%3E%3CPRE%20class%3D%22lia-code-sample%20language-yaml%22%3E%3CCODE%3E%23%20Azure%20Database%20for%20MySQL%20deployment%0A%0AapiVersion%3A%20azure.microsoft.com%2Fv1alpha2%0Akind%3A%20MySQLServer%0Ametadata%3A%0A%20%20%20%20%20name%3A%20mysqlappdbserver%0A%20%20%20%20%20labels%3A%20%23%20Provide%20tags%20to%20add%20to%20the%20KeyVault%20as%20labels%0A%20%20%20%20%20tag1%3A%20value1%0A%20%20%20%20%20tag2%3A%20value2%0Aspec%3A%0A%20%20%20%20%20location%3A%20eastus%0A%20%20%20%20%20resourceGroup%3A%20MyResourceGroup%0A%20%20%20%20%20serverVersion%3A%20%225.7%22%20%23%20could%20also%20be%208.0%0A%20%20%20%20%20sslEnforcement%3A%20Enabled%0A%20%20%20%20%20createMode%3A%20Default%20%23%20Possible%20values%20include%3A%20Default%2C%20Replica%2C%20PointInTimeRestore%20(not%20implemented)%2C%20GeoRestore%20(not%20implemented)%0A%20%20%20%20%20%23%20Optional%20admin%20secret%20name.%20If%20the%20admin%20secret%20is%20specified%20the%20%60username%60%20and%20%60password%60%20fields%20of%20the%20secret%20will%20be%20used%20to%20set%0A%20%20%20%20%20%23%20the%20administrator%20username%20and%20password.%20If%20adminSecret%20is%20not%20provided%2C%20ASO%20will%20generate%20an%20administrator%20account%0A%20%20%20%20%20%23%20and%20password.%0A%20%20%20%20%20%23%20adminSecret%3A%20my-admin-secret%0A%20%20%20%20%20sku%3A%0A%20%20%20%20%20%20%20%20%20%20name%3A%20GP_Gen5_4%0A%20%20%20%20%20%20%20%20%20%20tier%3A%20GeneralPurpose%20%23%20possible%20values%20-%20'Basic'%2C%20'GeneralPurpose'%2C%20'MemoryOptimized'%0A%20%20%20%20%20%20%20%20%20%20family%3A%20Gen5%0A%20%20%20%20%20%20%20%20%20%20size%3A%20%2251200%22%0A%20%20%20%20%20%20%20%20%20%20capacity%3A%204%0A%20%20%20%20%20%20%20%20%20%20%23%20Optional%20Backup%20Retention%20Config%0A%20%20%20%20%20%20%20%20%20%20%23%20storageProfile%3A%0A%20%20%20%20%20%20%20%20%20%20%23%20backupRetentionDays%3A%2010%0A%20%20%20%20%20%20%20%20%20%20%23%20geoRedundantBackup%3A%20Enabled%20%23%20Disabled%20or%20Enabled%0A%20%20%20%20%20%20%20%20%20%20%23%20storageMB%3A%205120%20%23%20max%20storage%20-%20minimum%20of%205120%20MB%20and%20additional%20increments%20of%201024%20MB%20up%20to%20maximum%20of%2016777216%20MB%0A%20%20%20%20%20%20%20%20%20%20%23%20storageAutogrow%3A%20Enabled%20%23%20Disabled%20or%20Enabled%0A---%0AapiVersion%3A%20azure.microsoft.com%2Fv1alpha1%0Akind%3A%20MySQLFirewallRule%0Ametadata%3A%0A%20%20%20%20%20name%3A%20mysqlfirewallrule-azureservices%0Aspec%3A%0A%20%20%20%20%20resourceGroup%3A%20MyResourceGroup%0A%20%20%20%20%20server%3A%20mysqlappdbserver%0A%20%20%20%20%20startIpAddress%3A%200.0.0.0%0A%20%20%20%20%20endIpAddress%3A%200.0.0.0%0A---%0AapiVersion%3A%20azure.microsoft.com%2Fv1alpha1%0Akind%3A%20MySQLDatabase%0Ametadata%3A%0A%20%20%20%20%20name%3A%20mydatabasename%0Aspec%3A%0A%20%20%20%20%20resourceGroup%3A%20MyResourceGroup%0A%20%20%20%20%20server%3A%20mysqlappdbserver%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BDeploy%26nbsp%3BMySQL%20server%20by%20running%20the%20following%20command%3A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Ekubectl%20appy%20-f%20myfile.yml%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3E%26nbsp%3BCheck%20the%20deployment%20status%20by%20running%20the%20following%20command%3A%3CBR%20%2F%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Ekubectl%20get%20MySqlServer%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3CBR%20%2F%3E%3CP%3EThe%20results%20will%20appear%20as%20shown%20in%20the%20following%20diagram.%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image4.PNG%22%20style%3D%22width%3A%20509px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F306426i321197DB25A41AB9%2Fimage-dimensions%2F509x58%3Fv%3Dv2%22%20width%3D%22509%22%20height%3D%2258%22%20role%3D%22button%22%20title%3D%22image4.PNG%22%20alt%3D%22image4.PNG%22%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3EThe%20server%20is%20now%20accessible%20via%20the%20Azure%20portal%20as%20well.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSTRONG%3ENote%3C%2FSTRONG%3E%3A%20You%20can%20explicitly%20provide%20the%20username%20and%20password%20in%20the%20YAML%20config%20file%2C%20or%20you%20can%20use%20them%20as%20environmental%20variables%20to%20connect%20your%20application%20to%20the%20server.%20The%20server%20name%2C%20username%2C%20and%20password%20are%20stored%20as%20keys%20in%20the%20secret%20generated%20by%20Kubernetes.%20To%20view%20the%20encoded%20keys%20run%20the%20following%20command%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Ekubectl%20describe%20secrets%20mysqlserver-mysqlappdbserver%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20similar%20output%20will%20appear%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image5.PNG%22%20style%3D%22width%3A%20634px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F306427i84332248916B8F3C%2Fimage-dimensions%2F634x301%3Fv%3Dv2%22%20width%3D%22634%22%20height%3D%22301%22%20role%3D%22button%22%20title%3D%22image5.PNG%22%20alt%3D%22image5.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EYou%20can%20reference%20the%20secret%20inside%20the%20YAML%20file%20for%20a%20pod%20that%20configures%20an%20app%20that%20needs%20to%20connect%20to%20the%20service%20in%20a%20deployment.%20The%20following%20example%20retrieves%20the%20values%20of%20the%20%3CEM%3EfullyQualifiedServerName%3C%2FEM%3E%2C%20%3CEM%3EfullyQualifiedUsername%3C%2FEM%3E%2C%20and%20%3CEM%3Epassword%3C%2FEM%3E%20keys%2C%20and%20makes%20them%20available%20as%20environment%20variables%20inside%20a%20pod.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-yaml%22%3E%3CCODE%3EapiVersion%3A%20apps%2Fv1%0Akind%3A%20Deployment%0Ametadata%3A%0A%20%20%20%20name%3A%20mysqlapp%0Aspec%3A%0A%20%20%20%20replicas%3A%204%0A%20%20%20%20selector%3A%20%0A%20%E2%80%A6%0A%20%20%20%20template%3A%20%0A%20%20%E2%80%A6%0A%20%20%20%20%20spec%3A%20%0A%20%20%E2%80%A6%0A%20%20%20%20%20%20%20%20%20containers%3A%20%0A%20%20%E2%80%A6%0A%20%20%20%20%20%20%20%20%20env%3A%0A%20%20%20%20-%20name%3A%20MYSQL_USER%0A%20%20valueFrom%3A%0A%20%20%20%20secretKeyRef%3A%0A%20%20%20name%3A%20mysqlserver-mysqlappdbserver%0A%20%20%20key%3A%20fullyQualifiedUsername%0A%20%20%20%20%20%20%20%20%20-%20name%3A%20MYSQL_PASSWORD%0A%20%20valueFrom%3A%0A%20%20%20%20secretKeyRef%3A%0A%20%20%20name%3A%20mysqlserver-mysqlappdbserver%0A%20%20%20key%3A%20password%0A%20%20%20%20%20%20%20%20%20-%20name%3A%20MYSQL_SERVICE_HOST%0A%20%20valueFrom%3A%0A%20%20%20%20secretKeyRef%3A%0A%20%20%20name%3A%20mysqlserver-mysqlappdbserver%0A%20%20%20key%3A%20fullyQualifiedServerName%0A%20%20%20%20%20%20%20%20%20-%20name%3A%20MYSQL_SERVICE_PORT%0A%20%20value%3A%20'3306'%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20application%20will%20retrieve%20environmental%20variables%20above%20and%20use%20them%20to%20construct%20a%20connector%20to%20the%20database%20server.%20The%20advantage%20of%20this%20approach%20is%20that%20connection%20credentials%20are%20not%20exposed%20to%20the%20app%2C%20reducing%20the%20chances%20of%20accidental%20disclosure.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESupportability%20note%3C%2FSTRONG%3E%3A%20This%20approach%20is%20also%20supported%20for%20Azure%20Database%20for%20PostgreSQL%2C%20Azure%20SQL%20Database%2C%20and%20Azure%20Cosmos%20DB.%20For%20more%20details%20and%20YAML%20code%20examples%2C%20please%20check%20the%20following%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-service-operator%2Ftree%2Fmaster%2Fconfig%2Fsamples%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Erepository%3C%2FA%3E.%20A%20list%20of%20ASO%20supported%20resources%20can%20be%20found%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2Fazure-service-operator%2Fissues%2F1192%23issuecomment-722766539%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2695317%22%20slang%3D%22en-US%22%3E%3CP%3ETo%20gain%20the%20benefits%20of%20using%20a%20MySQL%20database%20in%20a%20Kubernetes%20application%2C%20a%20common%20strategy%20is%20to%20provision%20the%20database%20in%20a%20container%20running%20in%20a%20pod.%20In%20doing%20so%2C%20the%20database%20will%20use%20the%20cluster%20resources.%20Accessing%20the%20database%20from%20other%20pods%20in%20the%20same%20AKS%20cluster%20running%20client%20apps%20is%20possible%20via%20Kubernetes%20networking.%20However%2C%20if%20for%20some%20reason%20cluster%20resources%20become%20unavailable%2C%20both%20the%20application%20and%20the%20database%20will%20be%20unavailable%2C%20as%20both%20rely%20on%20cluster%20health.%26nbsp%3BTo%20address%20this%20issue%2C%20you%20can%20substitute%20the%20local%20database%20in%20AKS%20with%20Azure%20Database%20for%20MySQL%2C%20which%20will%20separate%20the%20database%20from%20the%20AKS%20cluster.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22AKS%20blog.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F306823i2BC1BF065F0B0C98%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22AKS%20blog.png%22%20alt%3D%22AKS%20blog.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2695317%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAKS%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Service%20Operator%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMySQL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EProvisioning%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Sep 13 2021 09:57 AM
Updated by: