When running mysql in one pod, env MYSQL_ROOT_PASSWORD works as expected.
However, if running mysql with other containers in one pod, it seemed that "MYSQL_ROOT_PASSWORD" did not work as expected.
Although variable was set into mysql container, actually password is empty when connecting to mysql within container.
The detailed deployment is as below,
spec:
containers:
- name: ocai
image: aura/web:develop
imagePullPolicy: Always
ports:
- containerPort: 9000
- name: notebook
image: aura/all-spark-notebook:latest
imagePullPolicy: Always
ports:
- containerPort: 8889
command: ["sh", "-c", "jupyter-notebook --port=8889 --NotebookApp.token='secret' --config=/jupyter_notebook_config.py --no-browser"]
volumeMounts:
- mountPath: /data/ai_lab/ocai/
name: nb-data
resources:
requests:
memory: 4Gi
- name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: Ocai@1234
image: aura/mysql:5.7
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306
volumeMounts:
- mountPath: "/var/lib/mysql"
name: mysql-data
resources:
requests:
memory: 2G
volumes:
- name: mysql-data
persistentVolumeClaim:
claimName: ocai-mysql-claim
- name: nb-data
persistentVolumeClaim:
claimName: ocai-nb-claim
The problem was caused by persistent storage.
I didn't create pv/pvc correctly, so pod did not work as expected although it's started.
I also found that fi mounting hostPath as persistent storage, the pod failed to start.
Then I recreated PV/PVC, it worked well.
In your deployment config yaml, the env
value is only set for the mysql container. Therefore, even though they share the same pod, the environment variable will only be available to the mysql container.