Copy within pod curl to kubernetes dir

10/12/2019

Helllo does any one have an idea and can help here ?

  • I can not run a for me very complicated curl command i have some troubles to understand why its not working

I try to copy data via curl into a Wordpress Directory - at a POD from Kubernetes

kubectl exec $WPPOD -- curl --request GET --header 'PRIVATE-TOKEN: *******' 'https://gitlab.com/api/v4/projects/*****/repository/files/infrastructure%2Fwordpress%2Fdeploy%2Fall-in-one-wp-migration-unlimited-extension%2Ezip/raw?ref=Add_WP_MySQL' > /var/www/html/wp-content/ai1wm-backups                                     
sh: 7: cannot create  /var/www/html/wp-content/ai1wm-backups -: Directory nonexistent

Also from within the cube this is not working

# curl --request GET --header 'PRIVATE-TOKEN: Z7-RByYpUJcnWU_STpuz' 'https://gitlab.com/api/v4/projects/14628452/repository/files/infrastructure%2Fwordpress%2Fdeploy%2Fall-in-one-wp-migration-unlimited-extension%2Ezip/raw?ref=Add_WP_MySQL' > /var/www/html/wp-content/ai1wm-backups/all-in-one-wp-migration-unlimited-extension.zip -O -J -L
sh: 3: cannot create  /var/www/html/wp-content/ai1wm-backups/all-in-one-wp-migration-unlimited-extension.zip -O -J -L: Directory nonexistent

But if i check the directory within the cube it is fine

# cd /var/www/html/wp-content/ai1wm-backups
# ls
index.php  web.config

Thanks to the helpful input i have now a solution

kubectl exec $WPPOD -- curl --fail --output /var/www/html/wp-content/ai1wm-backups/all-in-one-wp-migration-unlimited-extension.zip --request GET --header 'PRIVATE-TOKEN: *******' 'https://gitlab.com/api/v4/projects/*****/repository/files/infrastructure%2Fwordpress%2Fdeploy%2Fall-in-one-wp-migration-unlimited-extension%2Ezip/raw?ref=Add_WP_MySQL'
-- Bliv_Dev
curl
kubectl
kubernetes

1 Answer

10/12/2019

You have two pieces of bad shell going on here:

The first one is because the redirection is happening on your machine. The second is because everything after the > is a filename, but you have included random arguments to curl in them.

To solve the first one, package the whole command into a shell literal:

kubectl exec $WPPOD -- sh -c "curl --request GET --header 'PRIVATE-TOKEN: *******' 'https://gitlab.com/api/v4/projects/*****/repository/files/infrastructure%2Fwordpress%2Fdeploy%2Fall-in-one-wp-migration-unlimited-extension%2Ezip/raw?ref=Add_WP_MySQL' > /var/www/html/wp-content/ai1wm-backups"

I would even go so far as to say "don't use redirection," since if you inform curl of the output file, and add --fail to it, then it will avoid writing to that file on server error, which isn't true when using a shell redirection: the shell will create that file, no matter what, possibly making it empty; thus:

kubectl exec $WPPOD -- curl --fail --output /var/www/html/wp-content/ai1wm-backups --request GET --header 'PRIVATE-TOKEN: *******' 'https://gitlab.com/api/v4/projects/*****/repository/files/infrastructure%2Fwordpress%2Fdeploy%2Fall-in-one-wp-migration-unlimited-extension%2Ezip/raw?ref=Add_WP_MySQL'

For the second problem, it's a simple matter of re-arranging the arguments to be compliant with shell syntax:

curl  -O -J -L --request GET --header 'PRIVATE-TOKEN: Z7-RByYpUJcnWU_STpuz' 'https://gitlab.com/api/v4/projects/14628452/repository/files/infrastructure%2Fwordpress%2Fdeploy%2Fall-in-one-wp-migration-unlimited-extension%2Ezip/raw?ref=Add_WP_MySQL' > /var/www/html/wp-content/ai1wm-backups/all-in-one-wp-migration-unlimited-extension.zip

Although in that case, you have conflicting curl behaviors: the -O option is going to write out the file in the current directory, so your shell redirect is only going to receive any messages written by curl, and not the content of that URL

All of this has nothing to do with kubernetes, or a directory, or a copy, and those tags should be removed.

-- mdaniel
Source: StackOverflow