In this lab you will use Kubernetes Persistent Storage constructs to mount a persistant volume store for a container. This exercise will use the Dynamic method instead of a static Persistent Volume
-
Create a Storage Class named
azuredsc
Create a storage class. Please use storage.k8s.io/v1beta1. You can see the spec in here
If you created the cluster with managed disks you must use
managed
as the StorageClass kind. If your Agents are using Storage Accounts for DataDisks then you must useshared
as the StorageClass kind.Deploy:
kubectl create -f config\storage-class.yaml
-
Create the Persistent Volume Claim named
mssql-pv-claim
Create a Persistent Volume Claim definition. You need to specify
storageClassName
on specification.Deploy:
kubectl create -f config\pv-claim.yaml
-
Deploy the
microsoft/mssql-server-linux
container.- Run with the volume
/var/opt/mssql
mounted from the PersistentVolumeClaim you created. - The mssql container requires 3 environment variables;
ACCEPT_EULA
with a value ofY
MSSQL_SA_PASSWORD
with a value of a complex password of at least 8 characters including uppercase, lowercase letters, base-10 digits and/or non-alphanumeric symbolsMSSQL_PID
with a value ofDeveloper
Deploy:
kubectl create -f config\mssql-store.yaml
- Run with the volume
-
Use
sqlcmd
to create a new database and a new table and insert some data into the table.exec
into the container by locating the pod name that mssql-deploy created$ kubectl exec mssql-store-***-*** -it bash root@mssql-store-***-***:/#
Connect to your service instance on port 1433
/opt/mssql-tools/bin/sqlcmd -S <INTERNAL_IP_OF_SERVICE>,1433 -U SA -P '<YourPassword>'
At the sqlcmd prompt create a new database
CREATE DATABASE TestDB GO
Verify the table was created
SELECT Name from sys.Databases GO
Set the DB context and create a new table called Inventory
USE TestDB CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT) GO
Insert data into the new table
INSERT INTO Inventory VALUES (1, 'penguins', 150); INSERT INTO Inventory VALUES (2, 'whales', 154); GO
Query the table to verify the data was written
SELECT * FROM Inventory WHERE quantity > 152; GO
Exit the
sqlcmd
toolQUIT
Exit your container session
exit
-
Determine the node the msqql pod is running on and drain the node.
You may have to use
--ignore-daemonsets
parameter to properly drain the node. You may have to use--delete-local-data
if jenkins is still running from the previous step.kubectl get node kubectl drain aks-nodepool1-***-* --ignore-daemonsets --delete-local-data
Once the node is showing no errors
kubectl uncordon aks-nodepool1-***-*
-
Verify that the new pod can access the data written by the old pod.
Use
kubcetl get all
to determine when the pod is finished recreating.Once the new pod is in a running state on a new node, connect to the database and query the Inventory table again to verify the data persisted.
- Try make a similar claim using AzureFiles.
- Use secrets to store the mssql credentials
- In the drain pod step, if jenkins is still running from the previous challenge, it's local data will be lost.