I want to create sample database for Sql server on Kubernetes

12/10/2021

I deployed sql server 2017 to my kubernetes and I want to put it a sample db such as northwind. There is no a gui for manage sql server. How Can I do that?

-- Onur AKKÖSE
devops
docker
kubernetes
sql-server

1 Answer

12/10/2021

You can forward your sql server port to localhost and then connect to the database using SQL Server Management Studio.

kubectl port-forward <sql-pod-name> <localhost-port>:<mssql-port>

For example:

kubectl port-forward mssql-statefulset-0 1433:1433

Then your database would be accessed on localhost.

enter image description here

Note that there is a comma between the address and the port.

If you manage to connect successfully, you can manually create the database using the SQL Server Management Studio tool.

Another way is to connect directly to your database container inside a pod using exec command and then execute sqlcmd commands.

kubectl exec -it <pod-name> -- /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'SA-password'

Or just like this

kubectl exec -it <pod-name> -- /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'SA-password' -Q 'CREATE DATABASE <database-name>'
-- Mikolaj
Source: StackOverflow