Creating SQL server Databases in AKS – Part 1

So, the point in the previous blog post was to leverage Persistent Volume Claims – PVC for data when using SQL server that it is needed in a stateful manner. But what happens when we don’t create SQL server in AKS without a PVC?

What are PVCs?  As Microsoft states “A PersistentVolumeClaim requests either Disk or File storage of a particular StorageClass, access mode, and size. The Kubernetes API server can dynamically provision the underlying storage resource in Azure if there is no existing resource to fulfill the claim based on the defined StorageClass.”

Please see this link for more details https://docs.microsoft.com/en-us/azure/aks/concepts-storage#persistent-volume-claims

Anyways, my YAML file is below with NO PVC established.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mssql-deploymentnopvc
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 

---
apiVersion: v1
kind: Service
metadata:
  name: mssql-deploymentnopvc
spec:
  selector:
    app: mssql
  ports:
    - protocol: TCP
      port: 1433
      targetPort: 1433
  type: LoadBalancer

I apply it and connect to service endpoint to via  SSMS.

The one called mssql-deploymentnopvc. I then connect and create a database and a sample table with some data.

I am now going to go to the underlying virtual machines (within a scale set) and stop and start them. These are the compute running my nodes in Azure.

Now I connect back to SQL server – guess what, everything is gone, hence why we need to setup a PVC, that is if you need to.

Next week, we will look at making this stateful.

Advertisement

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 )

Facebook photo

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

Connecting to %s