Run MSSQL 2019 on Kubernetes
Secret for sa
password
kubectl create secret generic mssql --from-literal=SA_PASSWORD="P@55word"
Storage
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mssql-data
annotations:
volume.beta.kubernetes.io/storage-class: default
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
Mount optional azure storage account
apiVersion: v1
kind: Secret
metadata:
name: mssql-optionalAddedStorage-secret
namespace: sqlserver
type: Opaque
data:
azurestorageaccountname: Z3NhcmNocG9jc3NoYXJlZHN0b3JhZ2U=
azurestorageaccountkey: SndPbTRlTFhLSVdWc1IzYkhONFV2WGlUM3NVSjBseHYvbUpQUU5DY1pYNEsyUmhTUjBZY3c5bzdmM3huU2h6bE9KVXhhSFcxT09KSmF4VktxRityVWc9PQ==
Values of azurestorageaccountname
and azurestorageaccountkey
are 64-based account name and key as extracted from Azure.
A File Share
needs to be created in the storage account and named optionalAddedStorage
, as referenced below.
Sql Server
There are optional values for the optional storage.
apiVersion: apps/v1
kind: Deployment
metadata:
name: mssql-deployment
spec:
replicas: 1
selector:
matchLabels:
app: mssql
template:
metadata:
labels:
app: mssql
spec:
terminationGracePeriodSeconds: 30
hostname: mssqlinst
securityContext:
fsGroup: 10001
containers:
- name: mssql
image: mcr.microsoft.com/mssql/server:2019-latest
ports:
- containerPort: 1433
env:
- name: MSSQL_PID
value: "Developer"
- name: ACCEPT_EULA
value: "Y"
- name: MSSQL_AGENT_ENABLED
value: "True"
- name: SA_PASSWORD
valueFrom:
secretKeyRef:
name: mssql
key: SA_PASSWORD
volumeMounts:
- name: mssqldb
mountPath: /var/opt/mssql
- name: optionalAddedStorage ## Optional storage
mountPath: /var/optionalAddedStorage
volumes:
- name: mssqldb
persistentVolumeClaim:
claimName: mssql-data
- name: optionalAddedStorage ## Optional storage
azureFile:
secretName: mssql-optionalAddedStorage-secret
shareName: optionalAddedStorage
readOnly: false
# nodeSelector:
# power: high
---
apiVersion: v1
kind: Service
metadata:
name: mssql-deployment
spec:
selector:
app: mssql
ports:
- protocol: TCP
port: 1433
targetPort: 1433
type: LoadBalancer