-
Notifications
You must be signed in to change notification settings - Fork 3
/
3.Persisting Data.ps1
183 lines (84 loc) · 2.89 KB
/
3.Persisting Data.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
############################################################################
############################################################################
#
# SQL Server & Kubernetes - Andrew Pruski
# @dbafromthecold
# https://github.com/dbafromthecold/SQLServerAndKubernetes
# Persisting Data
#
############################################################################
############################################################################
# confirm kubectl context
kubectl config current-context
# switch context to local cluster
kubectl config use-context docker-desktop
# navigate to script location
Set-Location C:\git\SQLServerAndKubernetes\yaml
# view storage class yaml
Get-Content storageclass.yaml
# create storage class
kubectl apply -f storageclass.yaml
# view storage class
kubectl get sc
# view persistent volume claim yaml
Get-Content persistentvolumeclaim.yaml
# create persistent volume claim
kubectl apply -f persistentvolumeclaim.yaml
# view persistent volume claim
kubectl get pvc
# view persistent volume
kubectl get pv
# describe persistent volume
kubectl describe pv
# create secret
kubectl create secret generic mssql --from-literal=MSSQL_SA_PASSWORD="Testing1122"
# view secret
kubectl get secrets
# describe secret
kubectl describe secret mssql
# try and get more info on secret
kubectl get secret mssql -o yaml
# decode secret
kubectl get secret mssql -o jsonpath='{ .data.MSSQL_SA_PASSWORD }' > C:\temp\passwd
certutil -decode C:\temp\passwd C:\temp\passwd_decode
cat C:\temp\passwd_decode
Remove-Item C:\temp\passwd; Remove-Item C:\temp\passwd_decode
get-content sqlserver_persistentvolume.yaml
# deploy sqlserver
kubectl apply -f sqlserver_persistentvolume.yaml
# view deployments
kubectl get deployments
# view pods
kubectl get pods
# view service
kubectl get service
# connect via mssql-cli
mssql-cli -S localhost -U sa -P Testing1122 -Q "SELECT @@VERSION AS [Version];"
# create a database
mssql-cli -S localhost -U sa -P Testing1122 -Q "CREATE DATABASE [testdatabase];"
# view databases
mssql-cli -S localhost -U sa -P Testing1122 -Q "SELECT [name] FROM sys.databases;"
# view database files
mssql-cli -S localhost -U sa -P Testing1122 -Q "USE [testdatabase]; EXEC sp_helpfile;"
# view pods with IP address
kubectl get pods -o wide
# delete pod
$PODNAME=$(kubectl get pods --no-headers -o custom-columns=":metadata.name")
kubectl delete pod $PODNAME
# view new pod's IP address
kubectl get pods -o wide
# view persistent volume claim
kubectl get pvc
# view volume
kubectl get pv
# view service
kubectl get service
# view databases
mssql-cli -S localhost -U sa -P Testing1122 -Q "SELECT [name] FROM sys.databases;"
# clean up
kubectl delete deployment sqlserver
kubectl delete service sqlserver-service
kubectl delete secret mssql
kubectl delete pvc mssql-data
kubectl delete sc test-sc