gpt4 book ai didi

docker - Openshift OC补丁未从/docker-entrypoint-initdb.d执行initdb.sql

转载 作者:行者123 更新时间:2023-12-02 21:04:27 24 4
gpt4 key购买 nike

OpenShift:

我有以下MySQL部署

apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-master
spec:
selector:
matchLabels:
app: mysql-master
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql-master
spec:
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: ro-mstr-nfs-datadir-claim
containers:
- image: mysql:5.7
name: mysql-master
env:
- name: MYSQL_SERVER_CONTAINER
value: mysql
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secret
key: MYSQL_ROOT_PASSWORD
- name: MYSQL_DATABASE
valueFrom:
secretKeyRef:
name: mysql-secret
key: MYSQL_DATABASE
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: mysql-secret
key: MYSQL_USER
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secret
key: MYSQL_PASSWORD
ports:
- containerPort: 3306
name: mysql-master
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql

我使用此yml文件创建了一个部署,该文件创建了一个成功运行的部署和pod。

我有一个配置图
apiVersion: v1
kind: ConfigMap
metadata:
name: ro-mstr-mysqlinitcnfgmap
data:
initdb.sql: |-
CREATE TABLE aadhaar ( name varchar(255) NOT NULL,
sex char NOT NULL, birth DATE NOT NULL, death DATE NULL,
id int(255) NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) );
CREATE USER 'usera'@'%' IDENTIFIED BY 'usera';
GRANT REPLICATION SLAVE ON *.* TO 'usera' IDENTIFIED BY 'usera';
FLUSH PRIVILEGES;

现在,我需要使用此configmap修补以上部署。我正在使用以下命令
oc patch deployment mysql-master -p '{ "spec": { "template": { "spec": { "volumes": [ { "name": "ro-mysqlinitconf-vol", "configMap": { "name": "ro-mstr-mysqlinitcnfgmap" } } ], "containers": [ { "image": "mysql:5.7", "name": "mysql-master", "volumeMounts": [ { "name": "ro-mysqlinitconf-vol", "mountPath": "/docker-entrypoint-initdb.d" } ] } ] } } } }'

因此,以上命令成功执行,我验证了Deployment描述,并在容器内部成功放置了initdb.sql文件,并重新创建了pod。但是问题在于它还没有创建aadhaar表。我认为它尚未执行 docker-entrypoint-initdb.d中的initdb.sql文件。

最佳答案

如果您进入图像(https://github.com/docker-library/mysql/blob/75f81c8e20e5085422155c48a50d99321212bf6f/5.7/docker-entrypoint.sh#L341-L350)中的入口点脚本,则可以看到它仅在首次创建数据库时才运行initdb.d文件。我认为您可能以为它总是在启动时运行它们?

关于docker - Openshift OC补丁未从/docker-entrypoint-initdb.d执行initdb.sql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58969127/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com