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

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

In this tutorial, we are going to connect and deploy Kubernetes resources through the Alibaba Cloud console.

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.


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.



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



  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:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

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


Step 4: Install "kubectl" Run the below command:

choco install kubernetes-cli

To check "kubectl" version, type the command below:

kubectl version


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.

echo $HOME

cd C:\

mkdir C:\Kubelet\ .kube

cd C:\Kubelet\ .kube

New-Item config -type file


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



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.

kubectl cluster-info 


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:

kubectl create secret generic mssql --from-literal=SA_PASSWORD="Pass@123db" 


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.



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


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

kind: PersistentVolumeClaim
apiVersion: v1
  name: mssql-data
  storageClassName: alicloud-disk-ssd #Change the Storage Class value
    - ReadWriteOnce
      storage: 30Gi

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


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


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


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).

apiVersion: apps/v1beta1
kind: Deployment
  name: mssql-deployment
  replicas: 1
        app: mssql
      terminationGracePeriodSeconds: 10
      - name: mssql
        image: microsoft/mssql-server-linux
        - containerPort: 1433
        - name: ACCEPT_EULA
          value: "Y"
        - name: SA_PASSWORD
              name: mssql
              key: SA_PASSWORD 
        - name: mssql-data
          mountPath: /var/opt/mssql
      - name: mssql-data
          claimName: mssql-data
apiVersion: v1
kind: Service
  name: mssql-deployment
    app: mssql
    - protocol: TCP
      port: 1433
      targetPort: 1433
  type: LoadBalancer

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


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


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.


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


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


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.



1 1 1
Share on

Alibaba Clouder

2,600 posts | 754 followers

You may also like


Dikky Ryan Pratama June 23, 2023 at 8:46 am