为什么在Pod中提取私有映像在Kubernetes Registry插件中不起作用?

时间:2017-05-14 12:59:33

标签: docker registry kubernetes kubectl

我是Kubernetes的新手,我设置Kubernetes注册表插件只需复制并粘贴来自Kubernetes Registry Addon的yaml只需ReplicationController 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

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

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)"]

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

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)

抛出错误

 protected void Page_Load(object sender, EventArgs e) { 
    if (!Page.IsPostBack) {
       loadgrid(); 
    }
 }
 private void loadgrid() {
 con.Open(); 
 cmd.CommandText = "SELECT TOP 4 * FROM [Question] ORDER BY NEWID()"; 
 cmd.Connection = con;
 SqlDataAdapter ad = new SqlDataAdapter(cmd); 
 DataTable dt = new DataTable();
 ad.Fill(dt);
 GridView1.DataSource = dt; 
 GridView1.AllowPaging = true; 
 GridView1.DataBind();

 }

知道为什么会这样吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

您的代理很可能无法使用。

Docker Registry K8S插件附带DaemonSet,它定义了符合你的kubelet的每个节点的注册表代理。我建议你检查那些代理,因为他们会将Docker Registry(K8S)服务映射到每个节点上的localhost:5000。

请注意,即使您的注册表代理上有绿色复选标记,也表示它们无法正常工作。打开它们的日志,确保一切正常。

如果您的代理已配置且仍然出现此错误,那么kube-registry-proxy中的环境变量REGISTRY_HOST很可能是错误的。您是否在这里使用DNS?您的DNS配置是否正确?如果将此变量放入服务的ClusterIP,它是否有效?

另外,请注意您的RC标签需要与SVC选择器匹配,否则服务无法发现您的吊舱。

希望它有所帮助。