This is the scenario: a SQL Server linux kubernetes setup with minikube.
It runs fine with default settings, databases/tables are created no problem.
But the database files should not be stored within the container so a PersistentVolumeClaim was added and the pod config changed to use the claim and mount /var/opt/mssql to /sqldata on the minikube VM.
apiVersion: v1
kind: PersistentVolume
metadata:
name: sqldata
spec:
capacity:
storage: 1Gi
storageClassName: sqlserver
accessModes:
- ReadWriteMany
hostPath:
path: "/sqldata"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: dbclaim
spec:
accessModes:
- ReadWriteMany
storageClassName: sqlserver
resources:
requests:
storage: 1Gi
apiVersion: v1
kind: Pod
spec:
initContainers:
- name: volume-permissions
image: busybox
command: ["sh", "-c", "chown -R 10001:0 /var/opt/mssql"]
volumeMounts:
- mountPath: "/var/opt/mssql"
name: sqldata-storage
volumes:
- name: sqldata-storage
persistentVolumeClaim:
claimName: dbclaim
containers:
- image: mcr.microsoft.com/mssql/server
name: foo
env:
- name: ACCEPT_EULA
value: "Y"
- name: SA_PASSWORD
valueFrom:
secretKeyRef:
name: sql-password
key: sa_password
- name: MSSQL_PID
value: Developer
volumeMounts:
- mountPath: "/var/opt/mssql/data"
name: sqldata-storage
Also tried image: microsoft/mssql-server-linux
chown -R 10001:0 /var/opt/mssql
is called in initcontainer to give mssql user access to the host VM's directory.
But what happens now is that the sql server pod starts up and after a minute or two it stops with a CrashloopBackoff.
The logfile from the pod says:
2020-08-02 14:33:57.55 Server Registry startup parameters: -d /var/opt/mssql/data/master.mdf -l /var/opt/mssql/data/mastlog.ldf -e /var/opt/mssql/log/errorlog 2020-08-02 14:33:57.78 Server Error 87(The parameter is incorrect.) occurred while opening file '/var/opt/mssql/data/master.mdf' to obtain configuration information at startup. An invalid startup option might have caused the error. Verify your startup options, and correct or remove them if necessary
Logging into the minikube VM, it looks like sql server does have access as the master table etc is created in the actual mounted directory although only owner permissions are set which is 10001:
$ ls -l /sqldata
-rw-r----- 1 10001 root 4194304 Aug 9 06:51 master.mdf
What to check for to get it running like this?