开发者社区> 问答> 正文

如何将Windows docker容器部署到docker-for-desktop Kubernetes集群?拉取访问被拒绝

k8s小能手 2019-02-22 15:38:40 682

我在桌面上运行docker并启用了kubernetes。我正在使用Windows容器(但也运行Linux容器 - 我将模式切换到Windows)。此外,kubernetes正在运行,但一直在使用Linux,所以我想集群中的单个节点正在使用Linux引擎,即使我已经将Docker切换为使用Windows容器。即使docker在Windows容器模式下运行,本地kubernetes集群似乎也无法加载Windows映像。

我试图解决以下错误:

Failed to pull image "iis-site": rpc error: code = Unknown desc = Error response from daemon: pull access denied for iis-site, repository does not exist or may require 'docker login'

重现步骤
我按如下方式构建了一个docker镜像:

FROM microsoft/iis

RUN powershell -NoProfile -Command Remove-Item -Recurse C:inetpubwwwroot*

WORKDIR /inetpub/wwwroot

COPY content/ .
我有这样的目录结构:

D:TEMPIIS
│ Dockerfile

└───content

    index.html

index.html看起来像这样:

<body>
Hello World!
</body>


我按如下方式运行容器:

docker build -t iis-site .
我可以导航到http:// localhost:8000 /,我可以看到我的网站!(成功)

在Kubernetes看到它
但现在我想看到它在kubernetes(本地集群)中运行。

我做

kubectl apply -f D:Tempwindows-deployment.yaml
d: TEMP Windows的deployment.yaml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: iis-deployment
spec:
replicas: 1
template:

metadata:
  labels:
    app: iis
spec:
  containers:
  - name: iis
    image: iis-site
    ports:
    - containerPort: 80

现在id做:

kubectl获得pods

NAME READY STATUS RESTARTS AGE
iis-deployment-5768b4fb85-pfxjk 0/1 ImagePullBackOff 0 18m
sql-deployment-659d64d464-rss5c 1/1 Running 18 40d
streact-deployment-567cf9db9b-g5vkb 1/1 Running 18 39d
web-deployment-669595758-7zcdx 1/1 Running 45 39d
现在我做

kubectl describe pod iis-deployment-5768b4fb85-pfxjk
Failed to pull image "iis-site": rpc error: code = Unknown desc = Error response from daemon: pull access denied for iis-site, repository does not exist or may require 'docker login'

附加信息
kubectl describe node docker-for-desktop

Name: docker-for-desktop
Roles: master
Labels: beta.kubernetes.io/arch=amd64

                beta.kubernetes.io/os=linux
                kubernetes.io/hostname=docker-for-desktop
                node-role.kubernetes.io/master=

Annotations: node.alpha.kubernetes.io/ttl=0

                volumes.kubernetes.io/controller-managed-attach-detach=true

CreationTimestamp: Fri, 11 Jan 2019 10:14:26 +0000
Taints:
Unschedulable: false
Conditions:
Type Status LastHeartbeatTime LastTransitionTime Reason Message
---- ------ ----------------- ------------------ ------ -------
OutOfDisk False Wed, 20 Feb 2019 16:32:37 +0000 Wed, 20 Feb 2019 10:06:38 +0000 KubeletHasSufficientDisk kubelet has sufficient disk space available
MemoryPressure False Wed, 20 Feb 2019 16:32:37 +0000 Wed, 20 Feb 2019 10:06:38 +0000 KubeletHasSufficientMemory kubelet has sufficient memory available
DiskPressure False Wed, 20 Feb 2019 16:32:37 +0000 Wed, 20 Feb 2019 10:06:38 +0000 KubeletHasNoDiskPressure kubelet has no disk pressure
PIDPressure False Wed, 20 Feb 2019 16:32:37 +0000 Fri, 11 Jan 2019 10:14:13 +0000 KubeletHasSufficientPID kubelet has sufficient PID available
Ready True Wed, 20 Feb 2019 16:32:37 +0000 Wed, 20 Feb 2019 10:06:38 +0000 KubeletReady kubelet is posting ready status
Addresses:
InternalIP: 192.168.65.3
Hostname: docker-for-desktop
Capacity:
cpu: 2
ephemeral-storage: 61664044Ki
hugepages-2Mi: 0
memory: 2540888Ki
pods: 110
Allocatable:
cpu: 2
ephemeral-storage: 56829582857
hugepages-2Mi: 0
memory: 2438488Ki
pods: 110
System Info:
Machine ID:
System UUID: 8776A14E-A225-4134-838E-B50A6ECAB276
Boot ID: 5a836f34-51a4-4adf-a32d-218a5df09b3c
Kernel Version: 4.9.125-linuxkit
OS Image: Docker for Windows
Operating System: linux
Architecture: amd64
Container Runtime Version: docker://18.9.2
Kubelet Version: v1.10.11
Kube-Proxy Version: v1.10.11
ExternalID: docker-for-desktop
Non-terminated Pods: (12 in total)
Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits
--------- ---- ------------ ---------- --------------- -------------
default iis-deployment-5768b4fb85-pfxjk 0 (0%) 0 (0%) 0 (0%) 0 (0%)
default sql-deployment-659d64d464-rss5c 0 (0%) 0 (0%) 0 (0%) 0 (0%)
default streact-deployment-567cf9db9b-g5vkb 0 (0%) 0 (0%) 0 (0%) 0 (0%)
default web-deployment-669595758-7zcdx 0 (0%) 0 (0%) 0 (0%) 0 (0%)
docker compose-74649b4db6-rm9zc 0 (0%) 0 (0%) 0 (0%) 0 (0%)
docker compose-api-fb7b8f78f-drllk 0 (0%) 0 (0%) 0 (0%) 0 (0%)
kube-system etcd-docker-for-desktop 0 (0%) 0 (0%) 0 (0%) 0 (0%)
kube-system kube-apiserver-docker-for-desktop 250m (12%) 0 (0%) 0 (0%) 0 (0%)
kube-system kube-controller-manager-docker-for-desktop 200m (10%) 0 (0%) 0 (0%) 0 (0%)
kube-system kube-dns-86f4d74b45-h2p5q 260m (13%) 0 (0%) 110Mi (4%) 170Mi (7%)
kube-system kube-proxy-p8vj7 0 (0%) 0 (0%) 0 (0%) 0 (0%)
kube-system kube-scheduler-docker-for-desktop 100m (5%) 0 (0%) 0 (0%) 0 (0%)
Allocated resources:
(Total limits may be over 100 percent, i.e., overcommitted.)
CPU Requests CPU Limits Memory Requests Memory Limits
------------ ---------- --------------- -------------
810m (40%) 0 (0%) 110Mi (4%) 170Mi (7%)
Events:
注意: 以上输出表明以下内容:

Operating System: linux
因此,即使docker引擎运行Windows容器,本地Kubernetes集群(控制平面)也在运行Linux。

我非常感谢有关如何修复上述错误的任何想法,即拉取访问被拒绝,以便我可以在Windows 10上使用Windows容器运行本地Kubernetes集群。

Kubernetes Linux Docker Windows 容器 Perl
分享到
取消 提交回答
全部回答(1)
  • k8s小能手
    2019-07-17 23:29:08

    您看到的错误与它是否可以运行或无法运行Windows容器无关,这是因为它无法提取图像。它看起来不像您将图像推送到docker hub。构建它之后,您需要运行:

    docker tag -t /iis iis
    docker push /iis
    您需要将docker hub凭据设置为部署中的ImagePullSecrets。然后你K8s部署:

    apiVersion: apps/v1beta1
    kind: Deployment
    metadata:
    name: iis-deployment
    spec:
    replicas: 1
    template:

    metadata:
      labels:
        app: iis
    spec:
      containers:
      - name: <yourdockerhubuser>/iis
        image: iis-site
        ports:
        - containerPort: 80
     imagePullSecrets:
     - name: <your-docker-hub-user-secret>

    好的,这个容器将无法运行,因为您的节点上有Linux,因此您需要拥有一个Windows节点,为此,您将在Windows计算机上设置kubelet。(我相信Docker for Windows不支持Windows kubelet,只支持在VM中运行的Linux kubelet)。

    0 0
+ 订阅

云原生时代,是开发者最好的时代

推荐文章
相似问题
推荐课程