我已经在我的Kubernetes集群上部署了mariadb-gallera,一旦部署了pod,并且它已经启动并运行,我想进入吊舱并以root身份登录到mysql,然后创建一个数据库,如果它不在那里。
我试过这样做,但由于错误而失败了:
name: "Run command on every Pod labelled app=glaera"
command: >
kubectl exec -i "{{ item }}" --namespace backend -- mysql -u'root' -p'YWRtaW4xMjM=' -- 'CREATE DATABASE IF NOT EXISTS aves';
with_items: "{{ pod_names }}"
请帮我找个解决办法。
错误:
failed: [localhost] (item=galera-mariadb-galera-0) => {"ansible_loop_var": "item", "changed": true, "cmd": ["kubectl", "exec", "-i", "galera-mariadb-galera-0", "--namespace", "backend", "--", "mysql", "-uroot", "-pYWRtaW4xMjM=", "--", "CREATE DATABASE IF NOT EXISTS aves;"], "delta": "0:00:00.190892", "end": "2021-02-02 11:57:37.806727", "item": "galera-mariadb-galera-0", "msg": "non-zero return code", "rc": 1, "start": "2021-02-02 11:57:37.615835", "stderr": "ERROR 1049 (42000): Unknown database 'CREATE DATABASE IF NOT EXISTS aves;'\ncommand terminated with exit code 1", "stderr_lines": ["ERROR 1049 (42000): Unknown database 'CREATE DATABASE IF NOT EXISTS aves;'", "command terminated with exit code 1"], "stdout": "", "stdout_lines": []}
发布于 2021-03-08 05:19:50
你的命令有个错误-
- name: "Run command on every Pod labelled app=glaera"
command: >
kubectl exec -i "{{ item }}" --namespace backend -- mysql -u'root' -p'YWRtaW4xMjM=' -e 'CREATE DATABASE IF NOT EXISTS aves';
with_items: "{{ pod_names }}"
注意,在'CREATE
之前应该有-e
。
另外,请使用k8s_exec
模块而不是command
模块。
例如,
- community.kubernetes.k8s_exec:
pod: mysql-deployment-5b68bb45bc-n98lp
namespace: default
command: mysql --defaults-file=client.conf -h 127.0.0.1 studentdb -e 'CREATE DATABASE IF NOT EXISTS aves'
https://stackoverflow.com/questions/66008385
复制相似问题