Shiny Tech Syndrome

This is the name I give to anyone who, whilst learning a new technology, suddenly thinks it’s the best thing since sliced bread and consequently wants to shoehorn it in to everything.

(think that person who just started learning NoSql)

I’m not singling anyone out here as we are all guilty of this at some point in our careers.

For me, it’s Linux. I’ve been interested in learning the platform for a while and have had tastes in the past when say, installing a redis cluster but I haven’t really delved that deep into it.

All that’s changed over the last year, with me digging into tech such as Kubernetes and of course, SQL on Linux being released. This has give me the chance (excuse?) and the opportunity to really start learning as there are now great resources for me in the shape of We Speak Linux and Anthony Nocentino’s (b|t) Plural Sight courses.

I have shiny tech syndrome so bad that I’m honestly considering buying a Dell XPS 13 with Ubuntu pre-installed as my next laptop.

At first that sounds a bit nuts for me. I’m a SQL Server DBA and want a lightweight laptop that I can use for presenting and writing blogs/demos.

But the more I think about it the more the XPS is appealing to me. I’ve been having some frustrations with Windows 10 recently (if I have to uninstall Candy Crush Saga after an update one more time I’m going to scream) and with the release of SQL Operations Studio & VS Code I can happily do everything that I need on a Linux laptop. Plus I have a Windows 10 Jump Box in Azure that I can always fall back to.

Are there any SQL Server DBAs out there who’ve used a Linux distro as their main working environment? Have you had any issues? I’d love to hear from you.

Have a good week!

T-SQL Tuesday #101: My Essential SQL Server Tools


This month’s T-SQL Tuesday topic comes from Jens Vestergaard (b|t) who is asking us about our essential SQL Server Tools.

I’ve previously written about my Tools of the Trade but that was waaaay back in April 2016 and just after I published that blog, the tool that I am going to talk about here was released, Visual Studio Code.

At first I used it sparingly, mainly for when writing demos but over the last few months Visual Studio Code has become invaluable to me.

My work has a large SQL estate to look after and I’ve found SSMS very frustrating as of late. It freezes up when dealing with multiple connections so I switched to using VS Code combined with dbatools.

What’s really cool is that you can setup custom tasks to easily run code against SQL instances, I blogged about how to set that up here.

I still use SSMS when drilling into a single instance (although Operations Studio is rapidly becoming more appealing) but when I want to audit instances or deploy, VS Code is now my go-to application.

Another thing that I love is the amount of plugins available. The Docker explorer and Azure-Cli plugins are absolutely fantastic. Combine that with the fact that I’ve recently moved all my code to GitHub and VS Code has built-in source control management, I’m finding that I’m spending more and more time using the application.

I highly recommend checking it out (if you haven’t already).

Thanks for reading!

Friday Reading 2018-04-06

Feels like an age since I posted some links. So busy these days!

I’m really excited today as tomorrow I head to North Carolina for two weeks. My company’s HQ is out there and I’m also presenting at SQL Saturday Raleigh next weekend. My first American SQL Sat! 🙂

Recently, when I’ve had the chance, I’ve been reading…

Troubleshooting SQL Server Scheduling and Yielding
Good post on the MSDN blogs about an issue that I’ve had to deal with recently

How to recover/rebuild Master Database in Linux?
I’ve been reading everything I can get my hands on about SQL on Linux and this is a cool post by Max Trinidad (t)

Procedure to Create New Filegroups and Files
Tracy (t) with a nice post on a stored proc to create new files and filegroups

When to use Quotes in PowerShell Splatting
Shane (t) with a tip when splatting

Rob Sewell talks about dbatools on RunAs Radio
Rob (b|t) talks about dbatools on the RunAsRadio podcast

Have a great weekend!

Changing the port for SQL Server in Azure Kubernetes Services

I got asked this question last week and it’s a very good one. After all, running Sql Server in Azure Container Services (AKS) does mean exposing a port to the internet to allow connections.


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


So leaving SQL Server listening on the default port can be risky.

Now I know there’s a debate as to whether or not it is worth changing the port that SQL is listening on in order to secure it. My opinion is that it’ll prevent opportunistic attacks by port scanners but would not prevent a directed attack.

So, how do you do it when running SQL Server in Azure Container Services?

Well there’s a couple of options available.

The first one is to change the port that SQL is listening on in the container, open that port on the container, and direct to that port from the service.

The second one is to leave SQL Server listening on the default port and direct a non-default port to port 1433 from the service.

Let’s run through both.

N.B. – Even though I’ll set this up from scratch I’d recommend you read through my previous post on AKS here


In order to set this up, I’ll use the Azure-CLI via Bash for Windows.

First thing to do is install the Azure-CLI: –

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

And install Kubectl: –

az aks install-cli

Then login to Azure: –

az login

Enable AKS on your Azure subscription: –

az provider register -n Microsoft.ContainerService

Create a resource group: –

az group create --name ApContainerResGrp1 --location centralus

And now we can create the cluster: –

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

N.B. – This can take some time

Once that’s complete we need to get credentials to connect to the cluster: –

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

Now test the connection by viewing the nodes in the cluster: –

kubectl get nodes

If both nodes come back with a status of Ready, you’re good to go!

Ok, so now let’s create the yaml file to spin up the container and service: –

nano sqlserver.yml

And drop this code into the file: –

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: 4433
        env:
        - name: SA_PASSWORD
          value: "Testing1122"
        - name: ACCEPT_EULA
          value: "Y"
        - name: MSSQL_TCP_PORT
          value: "4433"
---
apiVersion: v1
kind: Service
metadata:
  name: sqlserver-service
spec:
  ports:
  - name: sqlserver
    port: 4433
    targetPort: 4433
  selector:
    name: sqlserver
  type: LoadBalancer

N.B. – Code is also available here

Note the following code in the deployment section: –

        ports:
        - containerPort: 4433
.
.
.
        - name: MSSQL_TCP_PORT
          value: "4433"

This will use an environment variable to change the port that SQL is listening on to 4433 and open that port on the container.

Also note the following code in the service section: –

  ports:
  - name: sqlserver
    port: 4433
    targetPort: 4433

This will open the port 4433 externally and direct any connections to 4433 on the container.

So let’s deploy!

kubectl create -f sqlserver.yml

You can check the deployment process by running: –

kubectl get pods
kubectl get service

Once the pod has a status of Running and the service has an external IP, we can use the external IP and the port to connect to SQL in SSMS: –

And confirm that Sql is listening on the specified port by checking the log: –

EXEC sp_readerrorlog

Cool! Sql is listening on a non-default port and we’ve connected to it!

Alright, let’s try the next option.

First thing is to remove the old deployment: –

kubectl delete service sqlserver-service
kubectl delete deployment sqlserver
rm sqlserver.yml

Now let’s create the new yaml file: –

nano sqlsever.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: 4433
    targetPort: 1433
  selector:
    name: sqlserver
  type: LoadBalancer

N/B. – The code is also available here

Note the following in the service section:-

  ports:
  - name: sqlserver
    port: 4433
    targetPort: 1433

This opens port 4433 on the service and directs it to port 1433 in the container.

Rebuild the deployment: –

kubectl create -f sqlserver.yml

And once that’s created, connect on the service’s external IP and port 4433.

Awesome stuff! SQL is listening on the default port but we’ve connected to the port opened on the service and it has routed it to port 1433 opened on the container.

But which method would I recommend?

How about both! 🙂

Let’s change the default port that SQL is listening on and open a different port in the service!

Again, remove the old deployment: –

kubectl delete service sqlserver-service
kubectl delete deployment sqlserver
rm sqlserver.yml

Recreate the yaml file: –

nano sqlsever.yml

And the drop the following into the file: –

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: 4433
        env:
        - name: SA_PASSWORD
          value: "Testing1122"
        - name: ACCEPT_EULA
          value: "Y"
        - name: MSSQL_TCP_PORT
          value: "4433"
---
apiVersion: v1
kind: Service
metadata:
  name: sqlserver-service
spec:
  ports:
  - name: sqlserver
    port: 15789
    targetPort: 4433
  selector:
    name: sqlserver
  type: LoadBalancer

N.B. – This code is also available here

What’s happening here is that SQL will be configured to listen on port 4433 but we’ll connect externally to the service to port 15789 which is mapped to 4433 on the container.

Now redeploy: –

kubectl create -f sqlserver.yml

Same as before, wait for the container to be created and the service to have an external IP assigned: –

kubectl get pods
kubectl get service

Then use the external IP and the port 15789 to connect in SSMS: –

How cool is that?! SQL is listening on a non-default port and we’ve used a completely different port to connect!

Finally, to tear everything down: –

az group delete --name ApContainerResGrp1

Thanks for reading!

Imposter syndrome

Last week I posted the following “joke” on twitter: –

I’ve called it a “joke” but I wasn’t really joking. This is a subject that I’ve wanted to talk about for a while but have really stalled on it because I don’t think that I can tackle it sufficiently, but here goes anyway.

First things first, here’s the definition of Imposter (or Impostor) Syndrome: –

Impostor syndrome (also known as impostor phenomenon, fraud syndrome or the impostor experience) is a concept describing individuals who are marked by an inability to internalize their accomplishments and have a persistent fear of being exposed as a “fraud”

Sound like anyone you know?

OK, so here’s a (maybe) unpopular opinion.

I think Imposter Syndrome can be a good thing.

Let me explain why.

I get impostor syndrome, a lot. However I’ve learnt to recognise when it’s affecting me and can push through it. Don’t get me wrong, it still sucks. I question myself over and over but I don’t want my own head to stop me from achieving what I want.

I guess that this has come from experience. I’ve succeeded in a few things and a failed in a few as well.

And as much of a cliché as it is, I have learnt more from the failures than the successes.

I’ve failed and the world didn’t end. All that happened was that I needed to go back, review what went wrong, and make sure that it won’t happen again (I know that can be easier said than done).

So if you’re reading this and are thinking about starting to blog or speak or anything…I urge you to go for it.

Yes it’s hard work, you may fail, but the rewards for just trying are unbelievable.

All I can say is…Go for it 🙂

Have a good week!