Run Microsoft SQL Server Linux inside Kubernetes on VMware Tanzu

Run Microsoft SQL Server Linux inside Kubernetes on VMware Tanzu

My job is seldom boring and just this past week I had an interesting request come in asking,

“I wanted to pick your brains about running SQL Server on k8s, in our new platform?  I can’t find anything online about running SQL Server on Tanzu online”

My initial response was that there is no reason I can think of why that won’t be possible, but as I hadn’t read anything either I figured I’d spin up a lab, get it working and report back.

Run Microsoft SQL Server Linux inside Kubernetes on VMware Tanzu

First step is to create a namespace and link it to underlying storage.  This can be created through kubectl or through workload management within virtual centre.

Run Microsoft SQL Server Linux inside Kubernetes on VMware Tanzu

Persistent Volume Claim

In the image above you’ll see that I’ve already created the persistent volume claim for that namespace, which is the next step.  I’ve included sample yaml below for creating the PVC.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mssql-data-claim
spec:
  accessModes:
  - ReadWriteOnce
  storageClassName: vi-cluster1-vsan-storage-policy
  resources:
   requests:
    storage: 10Gi

This can be applied by running;

kubectl apply -f {yaml file name} -n {namespace}

Once created the status of the PVC can be checked either through VC or kubectl.

Run Microsoft SQL Server Linux inside Kubernetes on VMware Tanzu

Deployment Manifest

Next we can look at our deployment manifest itself.  Within the deployment yaml,

  • Creates a load-balancer listening on standard SQL port 1433
  • Creates a single replica
  • Defines the update criteria
  • Defines the amount of requested RAM
  • The container image, ‘microsoft/mssql-server-linux’
  • Specifying ports, passwords, accepting the EULA
  • Linking to the pre-created PVC
apiVersion: v1
kind: Service
metadata:
  name: mssql-deployment
spec:
  selector:
    app: mssql
  ports:
    - protocol: TCP
      port: 1433
      targetPort: 1433
  type: LoadBalancer

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mssql-deployment
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 0
  selector:
    matchLabels:
      app: mssql
  template:
    metadata:
      labels:
        app: mssql
    spec:
      restartPolicy: Always
      containers:
      - name: mssql
        resources:
          requests:
            memory: 8000Mi
        image: microsoft/mssql-server-linux
        ports:
        - containerPort: 1433
        env:
        - name: ACCEPT_EULA
          value: "Y"
        - name: SA_PASSWORD
          value: VMware123!
        volumeMounts:
        - name: mssql-persistent-storage
          mountPath: /var/opt/mssql
      volumes:
      - name: mssql-persistent-storage
        persistentVolumeClaim:
          claimName: mssql-data-claim

Deployment

With the deployment manifest created deployment is as simple as you might expect

kubectl apply -f {deployment yaml} -n {namespace}

Progress can be tracked with standard kubectl commands;

Result

Well the goal was to deploy a functional MS SQL Linux container.  To connect I fired up Azure Data Studio, directed it at the deployment load balancer on port 1433 and created a database.

Summary

Following standard kubernetes steps, I’ve deployed Microsoft SQL on Linux inside a VMware Tanzu Kubernetes container.  Feel free to use the manifests above to explore this functionality in your own environments.  This is however just demonstrating that this can be done, I would suggest that there are more considerations that need to be made to make this solution fit in with maintenance plans and be production ready.

Thanks

Simon

p.s. thanks to Dean for proof reading my YAML!