docker - How to initialize mysql container when created on Kubernetes? -


i want set initial data on mysql of container. in docker-compose.yml, such code can create initial data when running container.

volumes:   - db:/var/lib/mysql   - "./docker/mysql/conf.d:/etc/mysql/conf.d"   - "./docker/mysql/init.d:/docker-entrypoint-initdb.d" 

however, how can create initial data on kubernetes when running?

according mysql docker image readme, part relevant data initialization on container start-up ensure initialization files mount container's /docker-entrypoint-initdb.d folder.

you can define initial data in configmap, , mount corresponding volume in pod this:

apiversion: extensions/v1beta1 kind: pod metadata:   name: mysql spec:   containers:   - name: mysql     image: mysql             ports:       - containerport: 3306     volumemounts:       - name: mysql-initdb         mountpath: /docker-entrypoint-initdb.d   volumes:     - name: mysql-initdb       configmap:         name: mysql-initdb-config --- apiversion: v1 kind: configmap metadata:   name: mysql-initdb-config data:   initdb.sql: |     create table friends (id int, name varchar(256), age int, gender varchar(3));     insert friends values (1, 'john smith', 32, 'm');     insert friends values (2, 'lilian worksmith', 29, 'f');     insert friends values (3, 'michael rupert', 27, 'm'); 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -