Create An Azure Kubernetes Service Using Azure Portal
Step 1
Sign in to the Azure portal from
here.
Step 2
Create a new resource, select the category as Containers, and choose Kubernetes Service.
Step 3
Under “Basic” tab, select appropriate subscription, create/select resource group.
Provide a cluster name (), DNS name prefix (it is used to connect to the Kubernetes API when managing the containers after creating the cluster), the number of nodes, and their size based on your need (Node represents the number of agent servers, not the number of containers).
Note
The size of the node is not changeable once created, whereas you can change the number of nodes as per the requirement. Cost mentioned is per node cost, not the cost of the Azure Kubernetes Service (AKS) Cluster.
Step 4
Next, under the “Authentication” tab, create or use an existing service principle which has permissions to create and deploy the resources in a subscription. You can enable role-based access control (RBAC) if you require to provide permission to others over the resources in the cluster.
Step 5
Next, go to the “Networking” tab, create a new network, or click on Advance to select an existing VNet on which other resources are connected. You can select HTTP application routing if you are hosting a web application.
Step 6
For log monitoring and insights report, enable the container monitoring and create or select Log Analytics workspace on the “Monitoring” tab.
Step 7
On the next tab, you can add a tag to segregation if needed. Go to “Review + Create” tab after validation and click on "Create".
Note
You can download and keep the deployment if you are planning for automation or keeping the record of the deployment files.
After the successful deployment, you should be able to see your cluster, as shown below. But all the resources required for the cluster orchestration are created in different resource group (by default).
How to connect to Kubernetes Cluster
To manage the cluster and create applications, pods, etc., you need to connect using Azure CLI 2.0 which will launch the Kubernetes Web UI Management Interface. To connect to a cluster, click on the "View Kubernetes dashboard" option in your Kubernetes Cluster under the Overview section.
Note
These commands will not work on Cloud Shell and must be running on your local machine.
Step 1
Step 2
If you do not already have kubectl installed in your CLI, run the following command.
az aks install-cli
Step 3
Get the credentials for your cluster by running the following command.
az aks get-credentials --resource-group <ResourceGroupName> --name <ClusterName>
Note
The config file on the mentioned path is used as the authentication for Kubernetes Web UI management interface.
Step 4
Run the below-mentioned command to start a session on your localhost and launch the Kubernetes dashboard as shown below.
az aks browse --resource-group <ResourceGroupName> --name <ClusterName>
Deploy a SQL Server Container in Kubernetes with Azure Kubernetes Services (AKS) using Kubernetes Web UI Management Interface
You can configure a SQL Server instance on Kubernetes in Azure Kubernetes Service (AKS), with persistent storage for high availability (HA). The solution provides resiliency. If the SQL Server instance fails, Kubernetes automatically re-creates it in a new pod. Kubernetes also provides resiliency against node failure.
Step 1
Create an SA password (as Microsoft is still investing on Kerberos/AD in a Linux container
Link ).
Kubernetes can manage sensitive configuration information, like passwords as secrets
Open Azure CLI or local PowerShell and run get credentials command:
az aks get-credentials --resource-group <ResourceGroupName> --name <ClusterName>
The following command creates a password for the SA account:
kubectl create secret generic mssql --from-literal=SA_PASSWORD="Pass@123"
Step 2
Create persistent storage.
Create a manifest/ docker deployment script to define the storage class and the persistent volume claim, which specifies the storage provisioner, parameters, and reclaim policy.
The below-mentioned code represents an Azure Managed disk with 8GB storage of type standard HDD.
- kind: StorageClass
- apiVersion: storage.k8s.io/v1beta1 metadata: name: azure-disk
- provisioner: kubernetes.io/azure-disk parameters: storageaccounttype: Standard_LRS kind: Managed
- ---
- kind: PersistentVolumeClaim apiVersion: v1 metadata:
- name: mssql-data annotations:
-
- volume.beta.kubernetes.io/storage-class: azure-disk
- spec: accessModes: - ReadWriteOnce resources: requests:
- storage: 8Gi
To deploy the persistent storage on Azure Kubernetes Services (AKS), open your Kubernetes management portal.
Click on “Create” and paste the script, or you can save the above script as a yaml file and upload the script.
After uploading, navigate to “Persistent Volumes” blade and you could see the disk which is being created
Step 3
Create an SQL Server which uses the persistent storage to store the database.
Create a manifest/ docker deployment script which describe the container based on the SQL Server mssql-server-linux Docker image (make sure it fetches password from the secret created).
- apiVersion: apps/v1beta1 kind: Deployment metadata: name: mssql-deployment spec: replicas: 1 template: metadata: labels:
- app: mssql spec: terminationGracePeriodSeconds: 10 containers: - name: mssql
- image: mcr.microsoft.com/mssql/server/mssql-server-linux ports:
- - containerPort: 1433 env:
- - name: ACCEPT_EULA value: "Y" - name: SA_PASSWORD valueFrom: secretKeyRef: name: mssql key: SA_PASSWORD volumeMounts: - name: mssqldb
- mountPath: /var/opt/mssql volumes: - name: mssqldb persistentVolumeClaim: claimName: mssql-data
- ---
- apiVersion: v1 kind: Service metadata:
- name: mssql-deployment spec: selector: app: mssql ports:
- - protocol: TCP port: 1433 targetPort: 1433 type: LoadBalancer
To deploy the SQL Services on a container on Azure Kubernetes Services (AKS) go your Kubernetes management portal, click on “Create” and paste the script, or you can save the above script as a yaml file and upload the script.
To check the deployment status, go to “Deployments” blade and check for the deployment name, if deployment is successful you should see a green check as shown below. Go to Services blade to check your SQL Service and collect the Public IP and connect to SQL Server using SSMS.