我已使用以下Yaml创建了部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-slave
namespace: mysql-dr2
spec:
selector:
matchLabels:
app: mysql-slave
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql-slave
spec:
volumes:
- name: ro-slave-nfs-pv-datadir-vol
persistentVolumeClaim:
claimName: ro-slave-nfs-pvc-datadir-claim
- name: ro-slave-create-at-initcnfgmap-vol
configMap:
name: ro-slave-create-at-initcnfgmap
containers:
- image: mysql:5.7
name: mysql-slave
env:
- name: MYSQL_SERVER_CONTAINER
value: mysql-slave
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secret2
key: MYSQL_ROOT_PASSWORD
- name: MYSQL_DATABASE
valueFrom:
secretKeyRef:
name: mysql-secret2
key: MYSQL_DATABASE
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: mysql-secret2
key: MYSQL_USER
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secret2
key: MYSQL_PASSWORD
ports:
- containerPort: 3309
name: mysql-slave
volumeMounts:
- name: ro-slave-nfs-pv-datadir-vol
mountPath: /var/lib/mysql
- name: ro-slave-create-at-initcnfgmap-vol
mountPath: /docker-entrypoint-initdb.d/initdb-create-aadhaarTbl.sql
subPath: initdb-create-aadhaarTbl.sql
之后,我通过修补部署将文件放置在容器中
volumeMounts:
- mountPath: /docker-entrypoint-initdb.d/ro_slave_setup_sp.sql
name: ro-slave-repln-initcnfgmap-sp-vol
subPath: ro_slave_setup_sp.sql
现在我需要通过修补部署来再次执行此sql文件,为此,我将以下代码注入部署中
{
"spec": {
"template": {
"spec": {
"containers": [
{
"image": "mysql:5.7",
"name": "mysql-slave",
"lifecycle": {
"postStart": {
"exec": {
"command": [
"/bin/sh",
"-c",
"mysql -h localhost -P 3309 -uroot -ppassword < docker-entrypoint-initdb.d/ro_slave_setup_sp.sql"
]
}
}
}
}
]
}
}
}
}
此修补程序容器崩溃后出现以下错误
[rouser@ldblncr mysql-slave]$ oc get pods
NAME READY STATUS RESTARTS AGE
mysql-slave-565476d864-2slqc 0/1 PostStartHookError: command '/bin/sh -c mysql -h localhost -P 3309 -uroot -ppassword < docker-entrypoint-initdb.d/ro_slave_setup_sp.sql' exited with 1: mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (111)
1 73s
但是当我登录到容器并在其正常工作以下执行时。
mysql -uroot -ppassword -h localhost -P 3309 < docker-entrypoint-initdb.d/ro_slave_setup_sp.sql
请对此提供帮助。