Skip to content

Instantly share code, notes, and snippets.

@asears
Last active November 10, 2019 12:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save asears/f3c460ba8d23df2c1a985d5465cf79c3 to your computer and use it in GitHub Desktop.
Save asears/f3c460ba8d23df2c1a985d5465cf79c3 to your computer and use it in GitHub Desktop.
SQL on Linux on Kubernetes in Azure Containers

SQL on Linux on Kubernetes in Azure Linux Containers

Instead of Windows SQL container, let's try SQL on Linux!

https://dbafromthecold.com/2017/08/30/sql-server-in-kubernetes-clusters-on-acs/

Create Cluster

az acs create --orchestrator-type=kubernetes \
    --resource-group sqllinuxrg \
    --name=myK8sSQLCluster \
    --agent-count=2 \
    --generate-ssh-keys \
    --windows --admin-username andrew \
    --admin-password Testing1122

Create SQL Server Container

vi sqlserver.yaml
apiVersion: v1
kind: Pod
metadata:
  name: sqlserver
  labels:
    name: sqlserver
spec:
  containers:
  - name: sqlserver1
    image: microsoft/mssql-server-linux:2017-latest
    ports:
    - containerPort: 1433
    env:
    - name: SA_PASSWORD
      value: "Testing1122"
    - name: ACCEPT_EULA
      value: "Y"
  nodeSelector:
    beta.kubernetes.io/os: linux
kubectl apply -f sqlserver.yaml
az acs kubernetes get-credentials --resource-group=sqllinuxrg --name=myK8sSQLCluster
kubectl get nodes
kubectl get pods
kubectl logs sqlserver

Expose Port 1433

vi service.yaml
kind: Service
apiVersion: v1
metadata:
  name: sqlserver-service
spec:
  ports:
  - name: sqlserver
    port: 1433
    targetPort: 1433
  selector:
    name: sqlserver
  type: LoadBalancer
kubectl create -f service.yaml

Wait and wait until external IP address available

watch kubectl get svc

Start an ssh session

kubectl exec -it sqlserver -- /bin/bash
kubectl exec -it sqlserver ls -l /home

Install Git

https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-14-04

Install Dotnet and Azcopy

sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list' 
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893
apt-get update

apt-get install dotnet-dev-1.0.4

./azcopy --source https://sqlbackup.blob.core.windows.net/sqlbackup
--destination /home
--source-key mykey --include sqlbackup.bak

Install AzureFS

https://github.com/ahmetb/azurefs
https://azure.microsoft.com/en-us/blog/linux-fuse-adapter-for-blob-storage/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment