Connecting IaaS DBs with AKS in Enterprise Scenarios on Azure
In this article, we will discuss how to connect IaaS (Infrastructure-as-a-Service) databases with Azure Kubernetes Service (AKS) in an enterprise scenario on Azure. The current setup in the enterprise is fragmented, with AKS, Virtual Machines (VMs), and Backup subscriptions all separate from each other.
What is IaaS?
IaaS is a cloud computing model where the cloud provider manages the infrastructure, including servers, storage, and networking. The user is responsible for managing the operating systems, middleware, and applications. IaaS provides scalability, flexibility, and cost savings compared to traditional on-premises infrastructure.
What is Azure Kubernetes Service (AKS)?
AKS is a managed container orchestration service provided by Azure. It simplifies the deployment, scaling, and management of containerized applications. AKS supports popular container runtimes such as Docker and integrates with other Azure services such as Azure Monitor, Azure DevOps, and Azure Active Directory.
Connecting IaaS DBs with AKS
Connecting IaaS DBs with AKS involves configuring the network settings and access rules to allow communication between the two. Here are the high-level steps to connect IaaS DBs with AKS:
- Create an Azure Virtual Network (VNet) and subnet for AKS.
- Deploy AKS in the VNet subnet.
- Configure the IaaS DBs to allow traffic from the AKS subnet.
- Create a Kubernetes secret with the IaaS DB connection string.
- Use the Kubernetes secret in the application deployment YAML file.
Example: Connecting MySQL IaaS DB with AKS
Here is an example of connecting a MySQL IaaS DB with AKS:
Step 1: Create an Azure Virtual Network (VNet) and Subnet
Create an Azure Virtual Network (VNet) and subnet for AKS using the Azure portal or Azure CLI. Here is an example using Azure CLI:
az network vnet create --resource-group myResourceGroup --location eastus --name myVNet --subnet-name myAKSSubnet --address-prefixes 10.0.0.0/16 --subnet-prefixes 10.0.1.0/24
Step 2: Deploy AKS
Deploy AKS in the VNet subnet using the Azure portal or Azure CLI. Here is an example using Azure CLI:
az aks create --resource-group myResourceGroup --name myAKSCluster --location eastus --network-plugin azure --vnet-subnet-id /subscriptions/mySubscriptionID/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/myVNet/subnets/myAKSSubnet --generate-ssh-keys
Step 3: Configure the IaaS DB
Configure the IaaS DB to allow traffic from the AKS subnet. Here is an example for a MySQL IaaS DB:
GRANT ALL PRIVILEGES ON mydb.\* TO 'myuser'@'10.0.1.0/24' IDENTIFIED BY 'mypassword';
FLUSH PRIVILEGES;
Step 4: Create a Kubernetes Secret
Create a Kubernetes secret with the IaaS DB connection string. Here is an example using the Kubernetes command-line tool (kubectl):
kubectl create secret generic mydb-credentials --from-literal=username=myuser --from-literal=password=mypassword --from-literal=host=mydb.mysql.database.azure.com --from-literal=port=3306 --from-literal=database=mydb
Step 5: Use the Kubernetes Secret
Use the Kubernetes secret in the application deployment YAML file. Here is an example:
<!-- my-app-deployment.yaml -->
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app:1.0.0
env:
- name: MYSQL\_HOST
valueFrom:
secretKeyRef:
name: mydb-credentials
key: host
- name: MYSQL\_PORT
valueFrom:
secretKeyRef:
name: mydb-credentials
key: port
- name: MYSQL\_DATABASE
valueFrom:
secretKeyRef:
name: mydb-credentials
key: database
- name: MYSQL\_USERNAME
valueFrom:
secretKeyRef:
name: mydb-credentials
key: username
- name: MYSQL\_PASSWORD
valueFrom:
secretKeyRef:
name: mydb-credentials
key: password
Connecting IaaS DBs with AKS in an enterprise scenario on Azure involves configuring the network settings and access rules to allow communication between the two. The high-level steps include creating an Azure Virtual Network (VNet) and subnet for AKS, deploying AKS in the VNet subnet, configuring the IaaS DBs to allow traffic from the AKS subnet, creating a Kubernetes secret with the IaaS DB connection string, and using the Kubernetes secret in the application deployment YAML file. The example provided connects a MySQL IaaS DB with AKS.
References
- Azure Virtual Network (VNet) documentation: https://docs.microsoft.com/en-us/azure/virtual-network/virtual-networks-overview
- Azure Kubernetes Service (AKS) documentation: https://docs.microsoft.com/en-us/azure/aks/intro-kubernetes
- MySQL IaaS DB documentation: https://docs.microsoft.com/en-us/azure/mysql/overview
- Kubernetes secrets documentation: https://kubernetes.io/docs/concepts/configuration/secret/