Home > Net >  kubectl Pipe arguments to linux binary works from container shell interactive session, not through k
kubectl Pipe arguments to linux binary works from container shell interactive session, not through k

Time:10-25

echo "import /opt/tomcat/webapps/identityiq/WEB-INF/config/BLANKIdentity.xml" | /opt/tomcat/webapps/identityiq/WEB-INF/bin/iiq console)

This command works if kubectl exec -it [container] -n [namespace] -- /bin/bash and then run it from the console.

However, if I try to: kubectl exec [container] -n [namespace] -- echo "import /opt/tomcat/webapps/identityiq/WEB-INF/config/BLANKIdentity.xml" | /opt/tomcat/webapps/identityiq/WEB-INF/bin/iiq console

..it claims not to be able to find 'iiq'.

I've tried variables on relative vs. absolute pathing and am currently just defaulting to absolute paths to make sure nothing is getting lost in translation there.

I've also tried variations like: kubectl exec [container] -n [namespace] -- /bin/bash <(echo "import /opt/tomcat/webapps/identityiq/WEB-INF/config/BLANKIdentity.xml" | /opt/tomcat/webapps/identityiq/WEB-INF/bin/iiq console)

any suggestions?

CodePudding user response:

When you run kubectl exec ... <somecommand> | <anothercommand>, anything after the | is execute on your local host, not inside the remote container. It's just a regular shell a | b | c pipeline, where a in this case is your kubectl exec command.

If you want to run a shell pipeline inside the remote container, you'll need to ensure you pass the entire command line to the remote container, for example like this:

kubectl exec somepod -- sh -c '
  echo "import /opt/tomcat/webapps/identityiq/WEB-INF/config/BLANKIdentity.xml" |
  /opt/tomcat/webapps/identityiq/WEB-INF/bin/iiq console
'

Here, we're passing the pipeline as an argument to the sh -c command in the pod.

  • Related