0

I think this is related to powershell issue as it has worked on my mac (bash script).

Here's the one working in bash:

kubectl create secret docker-registry gcr-json-key \
        --docker-server=asia.gcr.io \
        --docker-username=_json_key \
        --docker-password="$(cat ./deploy/service-account.json)" \
        --docker-email=email@company.com.au

Here's one in powershell:

$key=$(Get-Content ./deploy/service-account.json)

kubectl create secret docker-registry 'gcr-json-key' `
        --docker-server='asia.gcr.io' `
        --docker-username='_json_key' `
        --docker-password=$key `
        --docker-email='email@company.com.au'

What could be wrong? is it because the quote is escaped in powershell when reading json file? I also realised that the kubectl script started giving error: exactly one NAME is required, got 5 when i included --docker-password with json content.

I tried a couple of things that didn't work as well such as putting flags to variable and tried escaping the quote in the json (assuming if that's the issue):

$param="--docker-server='asia.gcr.io' `
--docker-username='_json_key' `
--docker-password='$key' `
--docker-email='email@company.com.au'"

kubectl create secret docker-registry 'gcr-json-key' $param
Robert Tirta
  • 2,593
  • 3
  • 18
  • 37
  • Can you try to instead $key=$(Get-Content ./deploy/service-account.json) pass $key=(Get-Content ./deploy/service-account.json) – Malgorzata Feb 15 '21 at 11:06
  • @Malgorzata i did, it resulted the same. Now i'm sure its the `--docker-password` that is messing around in windows powershell. not sure how to escape this in kubectl commandline in windows – Robert Tirta Feb 15 '21 at 22:25
  • Did you take a look https://stackoverflow.com/questions/61249289/multi-parameters-in-powershell-bash-zsh-command ? – Malgorzata Mar 02 '21 at 11:45

0 Answers0