SQL Server and AKS

Following on from my last post after creating AKS, I now want to work with SQL server. First step, load up Azure cloud shell.

Run the following commands

az aks get-credentials --resource-group yourRG --name yourAKS

kubectl get nodes

Here you see the nodes I created from the previous post. Lets get to work with some SQL specific things. Setting SA.

kubectl create secret generic mssql --from-literal=SA_PASSWORD="whatever@ssw0rd"

Next  a need to create some storage, the nature of this technology if using databases means we have to use persistent volume claims.

kind: StorageClass
apiVersion: storage.k8s.io/v1
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

The run:

kubectl apply -f /home/arun/sqlstore2.yaml

Lets check:

In the Azure portal, within the AKS you will see:

Now before carrying on you may want to push a SQL image to your ACR and use that one. For this I am going direct to MCR to get image.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mssql-deployment
spec:
  replicas: 1
  selector:
     matchLabels:
       app: mssql
  template:
    metadata:
      labels:
        app: mssql
    spec:
      terminationGracePeriodSeconds: 30
      hostname: mssqlinst
      securityContext:
        fsGroup: 10001
      containers:
      - name: mssql
        image: mcr.microsoft.com/mssql/server:2019-latest
        ports:
        - containerPort: 1433
        env:
        - name: MSSQL_PID
          value: "Developer"
        - 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

I apply it.

Get services to check.

I then connect using our SA secret, SQL auth and the EX. IP above.

2 thoughts on “SQL Server and AKS

  1. Pingback: Dew Drop – July 30, 2021 (#3496) – Morning Dew by Alvin Ashcraft

  2. Pingback: ➧Dew Drop – July 30, 2021 (#3496) • Softbranchdevelopers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s