$ oc new-project mssql
$ oc create secret generic mssql --from-literal=SA_PASSWORD="Sql2019isfast"
$ oc apply -f https://raw.githubusercontent.com/erfinfeluzy/ocp4-notes/master/assets/mssql-storage.yaml
$ oc apply -f https://raw.githubusercontent.com/erfinfeluzy/ocp4-notes/master/assets/mssql-deployment.yaml
note:
- deployment uses image from microsoft mcr.microsoft.com/mssql/server:2017-CU8-ubuntu
- expose service as loadbalancer
Remote shell to mssql pods
$ oc get pods
$ oc rsh mssql-deployment-XXXXXXX
query inside pods
$ cd /opt/mssql-tools/bin
$ ./sqlcmd -S localhost -U sa -P Sql2019isfast
1> create database dbtest
2> select name from sys.databases
3> go
name
------------------------------
master
tempdb
model
msdb
dbtest
(5 rows affected)
1> use dbtest
2> create table tphone(id int, name nvarchar(50))
3> insert into tphone values(100,'Aina')
4> go
Changed database context to 'dbtest'.
(1 rows affected)
1> select * from tphone
2> go
id name
----------- --------------------------------------------------
100 Aina
(1 rows affected)
1> quit
- Step Service Type:LoadBalancer
- check load balancer url
$ oc get svc
============
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
mssql LoadBalancer 172.30.229.233 aa40ec02400a8488ca3db01d8b2db42b-1039870863.ap-southeast-1.elb.amazonaws.com 1433:31107/TCP 4h23m
mssql-service LoadBalancer 172.30.145.178 a126cecca8dff4f7996ec76e21491efc-1062532115.ap-southeast-1.elb.amazonaws.com 31433:31749/TCP 4h23m
use mssql-service to access from outside cluster eg: a126cecca8dff4f7996ec76e21491efc-1062532115.ap-southeast-1.elb.amazonaws.com:31433
$ oc apply -f https://raw.githubusercontent.com/erfinfeluzy/ocp4-notes/master/assets/dotnet-template-erfin.json
$ oc get pods
$ oc rsh mssql-deployment-XXXXXXX
Query inside mssql pods
$ cd /opt/mssql-tools/bin
$ ./sqlcmd -S localhost -U sa -P Sql2019isfast
1> use myContacts
2> go
Changed database context to 'myContacts'.
1> select * from Customers
2> go
Id Name
----------- ----------------------------------------------------------------------------------------------------
1 erfin2
2 aryo
(2 rows affected)
Add label to mssql deployment
app.kubernetes.io/name=mssql
Add label to dotnet deployment
app.kubernetes.io/name=dotnet