gpt4 book ai didi

kubernetes - 如何在 Windows 上(即在 PowerShell 中,而不是 Bash 中)为 Google Cloud Platform 添加 docker-registry secret?

转载 作者:行者123 更新时间:2023-12-02 11:33:17 29 4
gpt4 key购买 nike

我正在使用 Windows、启用了 Kubernetes 的 Windows 版 Docker 和 PowerShell(不是 Bash)。这仅用于本地测试我的 Docker 镜像和 Kubernetes 设置。我遇到的问题是无法访问 Google 的 Container Registry。

我创建了服务帐户,希望具有正确的权限,但我还没有。我有包含私钥和其他详细信息的 JSON 文件。我的问题是当我尝试通过运行来创建 secret 时:

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

我收到这个错误:

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

我的猜测是,在 --docker-password=" 之后,我得到了换行符、引号等,这是导致问题的原因。还是其他原因?我怎么了应该这样做吗?这在 Bash 中有效但在 PowerShell 中无效吗?

最佳答案

我能够通过转义双引号并从 JSON key 文件中删除新行来解决这个问题。 (电源外壳)

$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

关于kubernetes - 如何在 Windows 上(即在 PowerShell 中,而不是 Bash 中)为 Google Cloud Platform 添加 docker-registry secret?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53187226/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com