为什么拉在Pod中的私人图像不工作在Kubernetesregistry插件?

我是非常新的Kubernetes和我设置Kubernetes注册插件只是从Kubernetes注册插件复制和粘贴yaml只是一个小的改变ReplicationController with emptyDir

 apiVersion: v1 kind: ReplicationController metadata: name: kube-registry-v0 namespace: kube-system labels: k8s-app: kube-registry-upstream version: v0 kubernetes.io/cluster-service: "true" spec: replicas: 1 selector: k8s-app: kube-registry-upstream version: v0 template: metadata: labels: k8s-app: kube-registry-upstream version: v0 kubernetes.io/cluster-service: "true" spec: containers: - name: registry image: registry:2 resources: limits: cpu: 100m memory: 100Mi env: - name: REGISTRY_HTTP_ADDR value: :5000 - name: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY value: /var/lib/registry volumeMounts: - name: image-store mountPath: /var/lib/registry ports: - containerPort: 5000 name: registry protocol: TCP volumes: - name: image-store emptyDir: {} 

然后我转发5000端口如下

 $POD=$(kubectl get pods --namespace kube-system -l k8s-app=kube-registry-upstream \ -o template --template '{{range .items}}{{.metadata.name}} {{.status.phase}}{{"\n"}}{{end}}' \ | grep Running | head -1 | cut -f1 -d' ') $kubectl port-forward --namespace kube-system $POD 5000:5000 & 

我可以按照以下方式推送我的图片

 $docker tag alpine localhost:5000/nurrony/alpine $docker push localhost:5000/nurrony/alpine 

然后我写一个Pod来testing它,如下所示

 Version: v1 kind: Pod metadata: name: registry-demo labels: purpose: registry-demo spec: containers: - name: registry-demo-container image: localhost:5000/nurrony/alpine command: ["printenv"] args: ["HOSTNAME", "KUBERNETES_PORT"] env: - name: MESSAGE value: "hello world" command: ["/bin/echo"] args: ["$(MESSAGE)"] 

这是抛出一个错误

 Failed to pull image "localhost:5000/nurrony/alpine": image pull failed for localhost:5000/nurrony/alpine:latest, this may be because there are no credentials on this request. details: (net/http: request canceled) 

任何想法为什么发生这种情况? 提前致谢。

很有可能你的代理不工作。

Docker Registry K8S插件附带了DaemonSet,它定义了每个节点的registry代理,这个节点代表了你的kubelets。 我build议你检查这些代理,因为他们将Docker Registry(K8S)服务映射到每个节点上的localhost:5000。

请注意,即使您的registry代理上有绿色复选标记,但这并不意味着它们可以正常工作。 打开他们的日志,并确保一切正常。

如果你的代理configuration好了,而且你仍然收到这个错误,那么kube-registry-proxy里最可能的环境variablesREGISTRY_HOST是错误的。 你是否像在例子中使用DNS? 你的DNSconfiguration正确吗? 如果你把这个variables放到你的服务的ClusterIP上,它工作吗?

此外,请注意,您的RC标签需要与SVCselect器匹配,否则服务无法发现您的Pod。

希望能帮助到你。