2

我试图kubectl在虚拟机上运行。我按照此处给出的步骤进行了安装。我将本地 kubernetes 配置(从/Users/me/.kube/config)复制到目录中的 VM .kube。但是,当我运行任何命令时,例如kubectl get nodes它返回error: google: could not find default credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information

有没有办法可以kubectl在虚拟机上运行?

4

1 回答 1

1

要使用 kubectl 与非 Google VM 中的 Google Container Engine 集群通信,您可以创建一个用户管理的IAM 服务帐户,并使用它对您的集群进行身份验证:

# Set these variables for your project
PROJECT_ID=my-project
SA_NAME=my-new-serviceaccount
SA_EMAIL=$SA_NAME@$PROJECT_ID.iam.gserviceaccount.com
KEY_FILE=~/serviceaccount_key.json

# Create a new GCP IAM service account.
gcloud iam service-accounts create $SA_NAME

# Download a json key for that service account.
gcloud iam service-accounts keys create $KEY_FILE --iam-account $SA_EMAIL

# Give that service account the "Container Engine Developer" IAM role for your project.
gcloud projects add-iam-policy-binding $PROJECT_ID --member serviceAccount:$SA_EMAIL --role roles/container.developer

# Configure Application Default Credentials (what kubectl uses) to use that service account.
export GOOGLE_APPLICATION_CREDENTIALS=$KEY_FILE

然后像往常一样继续使用 kubectl。

于 2016-09-29T20:55:12.923 回答