How to Deploy a SQL Server Container in Alibaba Container Service Kubernetes

By Nadaraj Prabhu, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

In this tutorial, we will connect and deploy Kubernetes resources through the Alibaba Cloud console. First, we’ll see how we can connect a local machine to a Kubernetes cluster.

Prerequisites

Install a Kubernetes Cluster on Alibaba Cloud.

Connecting to Kubernetes Cluster

To manage the Kubernetes cluster, you need to connect to your cluster in using Cloud Shell CLI 2.0. It will help you execute “kubectl” command from local machine to “Kubernetes Services” which is hosted on Alibaba Cloud.

Step 1: To install “kubectl” on local machine, go to Alibaba Cloud Console Portal Link. select you “cluster” and click on “Manage” of your Kubernetes cluster.

Image for post
Image for post
Image for post
Image for post

Step 2: Scroll down and navigate to “Cluster Resource” Section and copy the key (kube config code).

Image for post
Image for post

Note:

  1. These commands will not work in cloud shell and must be running on your local machine.
  2. If you are planning to access the Kubernetes cluster using Public IP then copy Internet Access Code.
  3. If you have a VPN setup for this cluster then you can use VPN Access

Step 3: Go to your local machine, If you do not already have kubectl installed in your CLI. Open PowerShell/ CMD (as administrator) and install Chocolatey. Run the following command:

Note: I’m installing using Chocolatey method, you choose method your choice Link

Image for post
Image for post

Step 4: Install “kubectl” Run the below command:

To check “kubectl” version, type the command below:

Image for post
Image for post

Step 5: Change the path of to your directory and create a “config file” store connection Link, follow the commands below:

Below command will show your home and you need to keep the config fie there.

Image for post
Image for post

Step 6: Now go back to the cluster, browse for “KubeConfig”, copy the value and paste it in on local “config” file.

Image for post
Image for post
Image for post
Image for post

Note: The config file on the mentioned path is used as the authentication for Kubernetes Service to communicate with your local machine.

Step 7: Now type the below command to check whether you are connected you Kubernetes cluster.

Image for post
Image for post

You can leverage Cloud Shell’s functionality to create CusterRole, service, applications, pods, etc from local machine. In next topic will see how Cloud Shell help us create “secret” key which can store sensitive information. Like SQL Server “sa” Password etc.

Deploy a SQL Server Using Kubernetes Web UI Management Interface

You can configure a SQL Server instance on container using Kubernetes Service, with persistent storage for high availability (HA). The solution also provides high resilience. If the SQL Server instance fails, Kubernetes automatically re-creates it in a new pod. Kubernetes also provides resiliency against a node failure. In this demo we are going to deploy the resources though Kubernetes dashboard in Alibaba Cloud.

Step 1: Create an SA password.

Kubernetes can manage sensitive configuration information, like passwords as secrets.

The following command creates a password for the SA account:

Image for post
Image for post

Note: You can also create and verify from console under “secret” by opening “dashboard” of your “Kubernetes Cluster”.

To createSecret on Kubernetes Services, open select dashboard of your Kubernetes cluster.

Image for post
Image for post
Image for post
Image for post

Step 2: Create a 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.

Note: Make sure you replace “storage class” in the below script. You can get your storage classes name as shown below

Image for post
Image for post

Below mentioned code represents an Alibaba disk with 30GB storage of type standard SSD.

Step 3: To deploy the Persistent Volume Claim on Kubernetes Services, open select dashboard of your Kubernetes cluster.

Image for post
Image for post

Step 4: Click on “Create” and paste the script, or you can save the above script as yaml file and upload the script. Link 1

Image for post
Image for post

Step 5: Once the deployment is successful, navigate to “Persistent Volumes Claims” blade and you can see the disk which is being created.

Image for post
Image for post

Step 6: Create a 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).

Step 7: To deploy the SQL Services on a container of Kubernetes Services, go to your Kubernetes cluster and select “dashboard”

Image for post
Image for post

Step 8: click on “Create” and paste the script, or you can save the above script as yaml file and upload the script. Link 2

Image for post
Image for post

Step 9: 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.

Image for post
Image for post

Step 10: Go to Services blade to check your SQL Service and collect the Public IP.

Image for post
Image for post

Step 11: Now connect to SQL Server using SQL Server Management Tool (SSMS).

Image for post
Image for post

Now you have deployed SQL Server on kubernetes container with persistent storage and load balancer. SQL Server “SA” login password is stored in a secret vault, which makes it easy for you to swap whenever necessary. For monitoring purpose, navigate to “Overview” blade and check the status and heath of the nodes, services and pods.

Image for post
Image for post

References:

Original Source

https://www.alibabacloud.com/blog/how-to-deploy-a-sql-server-container-in-alibaba-container-service-kubernetes_594949?spm=a2c41.13076641.0.0

Written by

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store