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文件。我认为您可能以为它总是在启动时运行它们?

08-05 16:02