A brief snapshot of the conversation that my colleague and I had a couple of weeks ago:
Colleague: "I am new to Kubernetes and Linux world and was hoping if I could deploy SQL Server using helm chart from my Helm on my windows client and a managed kubernetes cluster service like Azure kubernetes service cluster (AKS)?"
Me: "Yes, you can!"
Colleague: "Great! Can you share articles or guidance to do that so I could follow those?"
Me: "hmm.. For Helm refer this.. for Kubernetes refer this.. For SQL Server deployment using helm on kubernetes refer this.. "
and that's when I noticed there wasn't a single stop end to end guidance. This is what prompted me to write this blog. And I hope this helps anyone who is new to Kubernetes/helm charts or even SQL Server and want to get started with the deployment of SQL Server on Kubernetes.
By the end of this blog, you should have the SQL Server deployed via the helm charts on the managed kubernetes service which in this case is Azure Kubernetes Service (AKS). For more information on Kubernetes, Helm chart please refer to articles mentioned below to get you started.
With the pre-read done, now lets start with deployment.
Please deploy an AKS (Azure Kubernetes Service) cluster. If you do not want to use AKS and want to create your custom kubernetes cluster you could do that as well.
On your windows client system, from where you will connect to the AKS cluster and deploy SQL Server using the helm chart below, the tools that need to be installed on the windows client are:
You first install "az", you can follow the steps documented here. From the link, download the current version of "az cli" exe and install the exe. If the installation is successful, you can type the command az in command prompt and if it is installed you should see output similar to the image shown below:
Choco install kubernetes-helm
Post the successful installation, when you run helm command in the cmd.exe you should see the output as shown below
az aks install-cli
Post the successful install of "kubectl" you should add the path to "kubectl" as one of the environment variables. In my case the path to kubectl is at "C:\Users\amitkh\.azure-kubectl" so I add the path to the environment variable as shown below:
With all the required tools installed on the windows client, we need to merge the context of the AKS cluster with the kubectl, so when we run kubectl or helm commands the operation takes place on that specific AKS cluster. To merge, run the command as described in the connect to aks cluster which is:
az aks get-credentials --resource-group <resourcegroupname> --name <aks clustername>
Once this is done, when you run a kubectl command the execution happens in the context of the aks cluster that we merged our tools with in the above step. An example shown below:
You are now ready to deploy the SQL Server on AKS cluster via the helm chart. You can download the sample helm-chart from this github location. Please go through the readme file to ensure you understand the options that you need or can change as per your requirement and customization.
Once you have the helm chart and all its file download to your windows client, switch to the directory where you have downloaded and after you have done modification to the downloaded helm chart to ensure it is as per your requirement and customization, deploy SQL Server using the command as shown below, you can change the deployment name ("mssql-latest-deploy") to anything that you'd like.
helm install mssql-latest-deploy . --set ACCEPT_EULA.value=Y --set MSSQL_PID.value=Developer
Here is a example for reference, I have the chart and its files downloaded to the mssql-latest directory and this is how it looks and then I run the helm install command to deploy SQL Server.
After a few minutes, you should see SQL Server deployed and ready to be used as shown below:
As you would have noticed in the helm chart, we provide a specific location for tempdb files to ensure that the tempdb files are stored in those specific location. Here are the steps you can follow:
-- Get the tempdb specific files
select * from sysaltfiles where dbid=2
--We want to move the tempdb files to this specific location : /var/opt/mssql/tempdb/, ---so here are the commands:
ALTER DATABASE tempdb
MODIFY FILE (NAME = tempdev, FILENAME = '/var/opt/mssql/tempdb/tempdb.mdf');
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = tempdev2, FILENAME = '/var/opt/mssql/tempdb/tempdb2.ndf');
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = templog, FILENAME = '/var/opt/mssql/tempdb/templog.ldf');
GO
--check and confirm that the locations for tempdb files are updated
select * from sysaltfiles where dbid=2
2. Now for the change to take in affect, you will have to restart the SQL Server container and you can do the same using the commands below:
kubectl scale deployment mssql-latest-deploy --replicas=0
Once you run the above command, wait for the container to be deleted and once it is, run the below command for the new container to be deployed
kubectl scale deployment mssql-latest-deploy --replicas=1
Here you can now connect to the pod and check the tempdb files are now located to the new location : /var/opt/mssql/tempdb/
Hope you enjoyed it !! Happy learning!!
Amit Khandelwal
Sr. Program Manager
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.