Bash commands connected using pipe(|) are not executed correctly in kubectl exec.
Example:
kubectl exec -ti <POD> -- pg_dump -h localhost -t my_table | psql -d <TARGET_DB> -h localhost
Here I want to run the pg_dump command first and redirect the output to the psql command as input using pipe(|).
But kubectl takes commands only until pipe character, pg_dump in my case and psql has been run on host machine instead of inside the <POD>.
The solution is to wrap all commands using double quote(") and run these commands using bash -c.