由于我没有通过 Terraform 使用标准 GKE 集群(请参阅gcr.io 上的 GKE 权限问题,使用基于 terraform 的服务帐户),我现在创建了一个具有单独节点池的集群。但是,我仍然无法从 eu.gcr.io 私人仓库中提取基本容器。
我的 terraform yml 如下。
resource "google_container_cluster" "primary" {
name = "gke-cluster"
location = "${var.region}-a"
node_locations = [
"${var.region}-b",
"${var.region}-c",
]
network = var.vpc_name
subnetwork = var.subnet_name
remove_default_node_pool = true
initial_node_count = 1
# minimum kubernetes version for master
min_master_version = var.min_master_version
master_auth {
username = var.gke_master_user
password = var.gke_master_pass
}
}
resource "google_container_node_pool" "primary_preemptible_nodes" {
name = "gke-node-pool"
location = "${var.region}-a"
cluster = google_container_cluster.primary.name
version = var.node_version
node_count = 3
node_config {
preemptible = true
metadata = {
disable-legacy-endpoints = "true"
}
# based on project number
service_account = "328126791642-compute@developer.gserviceaccount.com"
oauth_scopes = [
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only"
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring",
]
}
}
一切都创造得很好。然后我想在集群上部署
我使用以下 yml 文件 (deployment.yml) 创建这些部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-deployment
spec:
replicas: 1
selector:
matchLabels:
component: api
template:
metadata:
labels:
component: api
spec:
containers:
- name: api
image: eu.gcr.io/project-dev/api:latest
imagePullPolicy: Always
ports:
- containerPort: 5060
它继续给出:
Failed to pull image "eu.gcr.io/project-dev/api:latest": rpc error: code =
Unknown desc = Error response from daemon: pull access denied for eu.gcr.io/project-dev/api,
repository does not exist or may require 'docker login': denied: Permission denied for
"latest" from request "/v2/project-dev/lcm_api/manifests/latest".
警告 94 秒失败(x2 超过 111 秒)kubelet,gke-cluster-dev-node-pool-90efd247-7vl4 错误:ErrImagePull
我在 kubernetes 集群中有开放的云外壳,并且
docker pull eu.gcr.io/project-dev/api:latest
工作得很好。
我在这里的想法严重不足(并考虑回到 AWS)。它可能与容器被推送到 eu.gcr.io 的权限有关吗?
我用:
docker login -u _json_key --password-stdin https://eu.gcr.io < /home/jeroen/.config/gcloud/tf_admin.json
本地,其中 tf_admin.json 是创建基础结构项目的管理项目的服务帐户。然后我推
docker push eu.gcr.io/project-dev/api:latest
另一个想法。从文档和其他 stackoverflow 问题(参见例如GKE - ErrImagePull pull from Google Container Registry)看来,拥有正确的服务帐户和 oauth-scopes 似乎很关键。拉动时如何检查它是否使用了正确的服务帐户?范围是否正确分配?