Execute CURL with kubectl

8/30/2019

I am trying to execute curl command with kubectl like

kubectl exec POD_NAME "curl -X PUT http://localhost:8080/abc -H \"Content-Type: application/json\" -d '{\"name\":\"aaa\",\"no\":\"10\"}' "

Gives belob error

OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"kubectl exec POD_NAME "curl -X PUT http://localhost:8080/abc -H \"Content-Type: application/json\" -d '{\"name\":\"aaa\",\"no\":\"10\"}'\": 
stat kubectl exec POD_NAME "curl -X PUT http://localhost:8080/abc -H \"Content-Type: application/json\" -d '{\"name\":\"aaa\",\"no\":\"10\"}' ": no such file or directory" 
:unknown command terminated with exit code 126

I have tried to escape the quotes but no luck. Then I tried simple curl

kubectl exec -it POD_NAME curl http://localhost:8080/xyz

This gives proper output as excepted. Any help with this

Update:

But when I run interactive (kubectl exec -it POD_NAME /bin/bash) mode of container and then run the curl inside the container works like champ

-- Hitesh Ghuge
azure
azure-aks
azure-kubernetes
curl
kubernetes

1 Answer

8/30/2019

i think you need to do something like this:

kubectl exec POD_NAME curl "-X PUT http://localhost:8080/abc -H \"Content-Type: application/json\" -d '{\"name\":\"aaa\",\"no\":\"10\"}' "

what the error suggests is that its trying to interpret everything inside "" as a single command, not as a command with parameters. so its essentially looking for an executable called that

-- 4c74356b41
Source: StackOverflow