When working with SQL Server running containers the Error Log is written to standard out. Kubernetes will expose that information to you via kubectl. Let’s check out how it works.
If we start up a Pod running SQL Server and grab the Pod name
kubectl get pods NAME READY STATUS RESTARTS AGE mssql-deployment-56d8dbb7b7-hrqwj 1/1 Running 0 22m
We can use follow flag and that will continuously write the error log to your console, similar to using tail with the -f option. If you remove the follow flag it will write the current log to your console. This can be useful in debugging failed startups or in the case below, monitoring the status of a database restore. When finished you can use CTRL+C to break out and return back to your prompt.
kubectl logs mssql-deployment-56d8dbb7b7-hrqwj --follow
Will yield the following output
SQL Server 2019 will run as non-root by default. This container is running as user root. To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216. This is an evaluation version. There are [157] days left in the evaluation period. 2019-09-12 18:11:06.74 Server Setup step is copying system data file 'C:templatedatamaster.mdf' to '/var/opt/mssql/data/master.mdf'. 2019-09-12 18:11:06.82 Server Did not find an existing master data file /var/opt/mssql/data/master.mdf, copying the missing default master and other system database files. If you have moved the database location, but not moved the database files, startup may fail. To repair: shutdown SQL Server, move the master database to configured location, and restart. 2019-09-12 18:11:06.83 Server Setup step is copying system data file 'C:templatedatamastlog.ldf' to '/var/opt/mssql/data/mastlog.ldf'. 2019-09-12 18:11:06.85 Server Setup step is copying system data file 'C:templatedatamodel.mdf' to '/var/opt/mssql/data/model.mdf'. 2019-09-12 18:11:06.87 Server Setup step is copying system data file 'C:templatedatamodellog.ldf' to '/var/opt/mssql/data/modellog.ldf'. 2019-09-12 18:11:06.89 Server Setup step is copying system data file 'C:templatedatamsdbdata.mdf' to '/var/opt/mssql/data/msdbdata.mdf'. ...output omitted... 2019-09-12 18:11:12.37 spid9s Database 'msdb' running the upgrade step from version 903 to version 904. 2019-09-12 18:11:12.52 spid9s Recovery is complete. This is an informational message only. No user action is required. 2019-09-12 18:11:12.55 spid20s The default language (LCID 0) has been set for engine and full-text services. 2019-09-12 18:11:12.87 spid20s The tempdb database has 2 data file(s). 2019-09-12 18:14:29.78 spid56 Attempting to load library 'xpstar.dll' into memory. This is an informational message only. No user action is required. 2019-09-12 18:14:29.84 spid56 Using 'xpstar.dll' version '2019.150.1900' to execute extended stored procedure 'xp_instance_regread'. This is an informational message only; no user action is required. 2019-09-12 18:14:30.00 spid56 Attempting to load library 'xplog70.dll' into memory. This is an informational message only. No user action is required. 2019-09-12 18:14:30.05 spid56 Using 'xplog70.dll' version '2019.150.1900' to execute extended stored procedure 'xp_msver'. This is an informational message only; no user action is required. ...output omitted... 2019-09-12 18:32:32.40 spid66 [5]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1. 2019-09-12 18:32:32.41 spid66 Starting up database ‘DB1'. 2019-09-12 18:32:32.72 spid66 The database 'DB1' is marked RESTORING and is in a state that does not allow recovery to be run. 2019-09-12 18:32:37.44 Backup Database was restored: Database: DB1 creation date(time): 2019/05/11(13:32:05), first LSN: 148853:1000384:1, last LSN: 148853:1067344:1, number of dump devices: 1, device information: (FILE=1, TYPE=URL: {'https://yourenotallowtoknow.blob.core.windows.net/servername/DB1_FULL_20190912_020000.bak'}). Informational message. No user action required.
The post Using kubectl logs to read the SQL Server Error Log in Kubernetes appeared first on Centino Systems Blog.