Friday Reading 2018-01-11

Phew, what a week! Have been looking for a new flat to live so it’s been a bit mad. Have hopefully found a place, let the paperwork begin!

In between running around like a madman, I’ve been reading…

Free SQL Server Quizzes
Kendra Little (t) has written a whole bunch of tests on various aspects of SQL! Try your knowledge 🙂

RIP Swag Bags (and some other changes for SQL Relay 2018)
Alex Yates (t) drawing on experiences from SQL Relay 2017 and the changes to SQL Relay 2018

SQL Server 2017 CU2 Bug with msdb Compatibility Mode
Tracy Boggiano (t) details a bug with SQL Server 2017 CUs (yep, it’s in CU3 too)

SQL Server Configurations – Back to Basics
I’ve been working on automated checking of SQL config settings. Always good to have a refresher, here’s Jason Brimhall’s (t) back to basics article

Kubernetes Deployments Compared To Docker Swarm Stacks
With Docker announcing support for Kubernetes (it’s out for Docker on MAC), what is the difference between K8 & Swarm? Viktor Farcic (t) discusses

Have a good weekend!

Roll on 2018!

Hey everyone, hope you all had a great Christmas and New Year!

I took December off from blogging as had started a new job and wanted to focus on getting to grips with my new role. But back now and have a load of ideas for new blogs!

Going to keep looking at containers, initially focusing on Azure Container Services (AKS) but I’m waiting for Docker to release support for Kubernetes on Docker for Windows so will be jumping on that asap! I’m also going to presenting a couple of sessions on partitioning so will more than likely be posting a few blogs on that.

Looking back, 2017 was a great year for me. I went from presenting my first session at SQL Saturday Iceland to being made a Microsoft Data Platform MVP! Highlights include: –

  • Exploring Iceland after SQL Saturday (it’s an amazing country)
  • Presenting at SQL Bits for the first time (I was terrified)
  • Cycling through Copenhagen at around 9pm (the end of a long, stressful day)
  • Working with all the great ppl at SQL Relay (although I’ve never been so tired)

I’m hoping that 2018 is just as kind. I’ve already got a couple of session lined up so here’s to 2018, bring it on! 🙂

Have a good week!

Checking SQL Configuration with Pester & Dbatools

I know, I know, there’s loads of different ways to test the configuration of SQL Server but I’ve started playing around with Pester recently and it’s pretty cool!

The script I’ve written here will use Pester & Dbatools to check all settings in sys.configurations against values stored in a .csv file. The script will then alter the settings in SQL Server if they differ. So be warned!! 🙂

Here’s the script: –

Import-Module Pester
Import-Module dbatools

[string]$SqlServer = ''

$csv = Import-Csv .\ExampleServerConfigValues.csv
foreach($row in $csv){
        $ConfigName = $row.Name
        $ConfigValue = $row.Value

        $ConfigTest = Invoke-Pester -Script @{Path = '.\Test-SqlConfig.ps1'; `
            Parameters = @{SqlServer = $SqlServer; `
                ConfigName = $ConfigName; `
                    ConfigValue = $ConfigValue}} `
                        -TestName '*Testing configuration*' `
                            -PassThru

        $ConfigTest.TestResult.foreach{
            if($_.Result -ne "Passed"){
                Write-Host "Setting $ConfigName on $SqlServer..." -ForegroundColor Yellow
                    Set-DbaSpConfigure -SqlInstance $SqlServer -ConfigName $ConfigName -Value $ConfigValue
            }
        }   
    }

N.B. – This can easily be altered to reference, say, a Central Management Server that holds the server names to test and the desired config values

The Pester test [.\Test-SqlConfig.ps1] that it’s referencing is: –

param(
    [Parameter(Mandatory)] 
    [ValidateNotNullOrEmpty()]
    [string]$SqlServer,
    [string]$ConfigName,
    [string]$ConfigValue
)

Describe "Testing configuration $ConfigName of Sql Instance $SqlServer"{
    Context "SqlConfig"{
        It "$ConfigName should be $ConfigValue"{
            $value = Get-DbaSpConfigure -SqlServer $SqlServer -Config $ConfigName
            $value.ConfiguredValue | Should be $ConfigValue
        }
    }
}

N.B. – This code is also on GitHub here.

So run the first script and, BOOM!

One Pester test running!

What I like about this is that it can be easily dropped into a job scheduler (e.g.- Jenkins) and then you’ve got a way to routinely check (and correct) all the configuration settings of the SQL instances that you monitor.

Thanks for reading!

Friday Reading 2017-11-17

Fun week, lots of stuff to organise and prepare for! Whilst I’ve had some downtime I’ve been reading…

Write your first Pester test today
Rob (t) takes us through the steps to write a Pester test (something I’ve been meaning to do for ages)

How To Enlarge Your Columns With No Downtime
Gianluca (t) demonstrates how to make column enlargement less painful

Do not pass GO
Monica Rathbun (t) talks about the GO statement in SSMS

Streamlining SQL Server Management Objects (SMO) in PowerShell Core
Max Trinidad’s (t) cool post on using SMO objects

Introducing Visual Studio Live Share
VS Blog detailing the new Live Share feature (this looks very cool)

Have a good weekend!

Running SQL Server in Kubernetes on Azure Kubernetes Services (AKS)

I’ve previously blogged about running SQL Server in ACS but Microsoft has now released a new version still called Azure Container Services (AKS instead of ACS however) but now specifically tailored to building Kubernetes clusters.


EDIT – Azure Container Services (AKS) has been renamed to Azure Kubernetes Services. Blog title has been updated


There are some differences to the original ACS (making the process simpler) so let’s run through setting up a Kubernetes cluster running SQL Server in AKS.

Ok, first thing to do is install the CLI (I’m going to work from a Bash shell on my desktop): –

echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \
     sudo tee /etc/apt/sources.list.d/azure-cli.list
	 
	 
sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 52E16F86FEE04B979B07E28DB02C46DF417A0893
sudo apt-get install apt-transport-https
sudo apt-get update && sudo apt-get install azure-cli

Check the version of the CLI installed (make sure it’s at least version 2.0.20): –

az --version

Then login to Azure in the shell (and follow the instructions): –

az login

As AKS is still in preview a flag needs to be enabled on your Azure subscription.
To do this run: –

az provider register -n Microsoft.ContainerService

You can check that the flag has been successfully enabled by running: –

az provider show -n Microsoft.ContainerService

Cool. Now we’re good to go with setting up a Kubernetes cluster! Same as the original ACS, a resource group needs to be created to hold all the objects in the cloud: –

az group create --name ApResourceGroup1 --location ukwest

And now the cluster can be created. I’m going to create a two node cluster by running: –

az aks create --resource-group ApResourceGroup1 --name mySQLK8sCluster1 --node-count 2 --generate-ssh-keys


EDIT: updated agent-code to node-count has this switch seems to have changed since I wrote this post

What’s cool about this is the amount of objects it’s creating in the background: –

All that from one line of code!

Once that’s complete, Kubectl needs to be installed locally to manage the cluster: –

az aks install-cli

And then I need to connect my local shell to the cluster: –

az aks get-credentials --resource-group ApResourceGroup1 --name mySQLK8sCluster1

Ok, let’s check the nodes in the cluster: –

kubectl get nodes

Awesome, I have two nodes up and running in my cluster!

Next thing to do is spin up SQL Server in a container within the cluster. To do this I’m going to build it from a yaml file: –

nano sqlserver.yml

And drop the following into it: –

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: sqlserver
  labels:
    app: sqlserver
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: sqlserver
    spec:
      containers:
      - name: sqlserver1
        image: microsoft/mssql-server-linux:latest
        ports:
        - containerPort: 1433
        env:
        - name: SA_PASSWORD
          value: "Testing1122"
        - name: ACCEPT_EULA
          value: "Y"
---
apiVersion: v1
kind: Service
metadata:
  name: sqlserver-service
spec:
  ports:
  - name: sqlserver
    port: 1433
    targetPort: 1433
  selector:
    name: sqlserver
  type: LoadBalancer

This will spin up a container within the cluster (as a deployment) and create a load balanced service with an external IP so that I can connect to SQL Server from my desktop. So now run: –

kubectl create -f sqlserver.yml

Once that’s complete we can run some commands to view the objects created. To check the SQL Server container created: –

kubectl get pods

To check on the deployment:-

kubectl get deployments

And finally, to check on the service: –

kubectl get service

Once the service has an external IP, I can use that to connect to SQL Server within my Kubernetes cluster in AKS!

How awesome is that! Microsoft have made this a nice and simple way of getting into running Kubernetes in Azure. I’m going to play around with this some more 🙂

Last thing, to remove all the objects built in this demo you just need to run: –

az group delete --name ApResourceGroup1

Thanks for reading!