Created
March 9, 2021 04:40
-
-
Save Akasurde/600190a33707f8cc260f246c00f0e10a to your computer and use it in GitHub Desktop.
Create MySQL database pod with preloaded data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: mysql-deployment | |
labels: | |
app: mysql | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: mysql | |
template: | |
metadata: | |
labels: | |
app: mysql | |
spec: | |
containers: | |
- name: mysql | |
image: mysql:5.7 | |
ports: | |
- containerPort: 3306 | |
env: | |
- name: MYSQL_ROOT_PASSWORD | |
valueFrom: | |
secretKeyRef: | |
name: mysql-secrets | |
key: ROOT_PASSWORD | |
volumeMounts: | |
- name: mysql-initdb | |
mountPath: /docker-entrypoint-initdb.d | |
- mountPath: "/var/lib/mysql" | |
subPath: "mysql" | |
name: mysql-data | |
volumes: | |
- name: mysql-initdb | |
configMap: | |
name: mysql-initdb-config | |
- name: mysql-data | |
persistentVolumeClaim: | |
claimName: mysql-data-disk | |
--- | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: mysql-initdb-config | |
data: | |
init.sql: | | |
CREATE DATABASE IF NOT EXISTS mydata; | |
USE mydata; | |
CREATE TABLE friends (id INT, name VARCHAR(256), age INT, gender VARCHAR(3)); | |
INSERT INTO friends VALUES (1, 'Abhijeet', 32, 'm'); | |
INSERT INTO friends VALUES (2, 'Anjali', 29, 'f'); | |
INSERT INTO friends VALUES (3, 'Aayush', 27, 'm'); | |
--- | |
apiVersion: v1 | |
kind: PersistentVolumeClaim | |
metadata: | |
name: mysql-data-disk | |
spec: | |
accessModes: | |
- ReadWriteOnce | |
resources: | |
requests: | |
storage: 1Gi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment