刚接触kubernetes和php,所以我遇到了一些问题。任何和所有的帮助是非常感激!
<?php
$postgres = 'kubectl get pods -n migrationnamespace | grep postgres | cut -d " " -f1 2>&1';
$postgres_pod = shell_exec($postgres);
echo $postgres_pod;
$list2 = 'kubectl exec -it -n migrationnamespace ' . $postgres_pod . ' -- psql -U postgres -c 'SELECT * FROM mywhales'; 2>&1';
echo "<pre>";
echo shell_exec($list2);
echo "<pre>";
?>
导致错误
postgres-7957478b7d-tmw6m
error: you must specify at least one command for the container
sh: line 1: --: command not found
当将'.$postgres_pod.'
切换为postgres-7957478b7d-tmw6m
时,它完全执行
$list2 = 'kubectl exec -it -n migrationnamespace postgres-7957478b7d-tmw6m -- psql -U postgres -c 'SELECT * FROM mywhales';';
postgres-7957478b7d-tmw6m
whale
---------
16:117
......
561:539
(17 rows)
Thanks - Mike
有时字符串前后可能有额外的空白,特别是在echo
结果时不总是显示的返回字符。
使用trim($postgres_pod)
将确保它们被移除。