<p>I'm using Windows, Docker for Windows with Kubernetes enabled and PowerShell (not Bash). This is just for local testing of my Docker images and Kubernetes set up. The problem I'm having is getting access to Google's Container Registry.</p>

<p>I created the service account, hopefully with the right permissions but I'm not there yet. I've got the JSON file with the private key and other details. My problem is when I try to create the secret by running:</p>

<pre><code>kubectl create secret docker-registry gcr-json-key --docker-server=eu.gcr.io --docker-username=_json_key --docker-password="$(cat json_credentials.json)" --docker-email=pupeno@example.com
</code></pre>

<p>I get this error:</p>

<pre><code>error: exactly one NAME is required, got 5
See 'kubectl create secret docker-registry -h' for help and examples.
</code></pre>

<p>My guess is that after <code>--docker-password="</code> I end up with line-feeds, quotes, etc. and that is causing the problem. Or is it something else? How am I suppose to do it? Does this work in Bash but not PowerShell? </p>

<p>I was able to solve this issue by escaping double quotes and removing new lines from the JSON key file. (Powershell)</p>

<pre><code>$JSON_CREDS = "C:\Path\To\Creds.json"
$REPOSITORY_HOST = "https://gcr.io"
$EMAIL = "email@example.com"
# An arbitrary string to serve as the name of the secret
$SECRET_NAME = "gcr-pull-secret"
$KUB_NAMESPACE = "some-namespace"

$service_json = (Get-Content $JSON_CREDS).replace("\n", "").replace('"', '\"')

$kubePath = "C:\Path\To\kubectl.exe"
$namespaceArg = "--namespace=$KUB_NAMESPACE"
$createArg = "create secret docker-registry $SECRET_NAME"
$serverArg = "--docker-server=$REPOSITORY_HOST"
$usernameArg = "--docker-username=_json_key"
$passwordArg = "--docker-password=""$service_json"""
$emailArg = "--docker-email=$EMAIL"

Start-Process $kubePath -ArgumentList "$namespaceArg $createArg $serverArg $usernameArg $passwordArg $emailArg" -Wait -NoNewWindow

# Optional, used to patch the default service account

$imagePullSecretJson = """{\""imagePullSecrets\"": [{\""name\"": \""$SECRET_NAME\""}]}"""

Start-Process $kubePath -ArgumentList "patch serviceaccount default -p $imagePullSecretJson" -Wait -NoNewWindow
</code></pre>
