简体   繁体   中英

How do I deploy Windows docker containers to docker-for-desktop Kubernetes cluster? pull access denied

I am running docker for desktop with kubernetes enabled. I am using Windows containers (but have also been running Linux containers - I switched modes to Windows). Also, kubernetes is running, but has been using Linux, so I guess the single node in the cluster is using the Linux engine, even though I have switched Docker to use Windows containers. It appears that the local kubernetes cluster is not able to load the Windows image, even though docker is running in Windows container mode.

I am trying to solve the following error:

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'

Steps to reproduce

I build a docker image as follows:

FROM microsoft/iis

RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\*

WORKDIR /inetpub/wwwroot

COPY content/ .

I have a directory structure like this:

D:\TEMP\IIS
│   Dockerfile
│
└───content
        index.html

index.html looks like this:

<html>
    <body>
    Hello World!
    </body>
</html>

I run up the container as follows:

docker build -t iis-site .

I can navigate to http://localhost:8000/ and I can see my website! (SUCCESS)

See it in Kubernetes

But now I want to see it running in kubernetes (local cluster).

I do

kubectl apply -f D:\Temp\windows-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

Now id do:

kubectl get 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

Now I do

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'

Additional info

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:             <none>
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:         <none>

Note: The above output indicates the following:

 Operating System:           linux

So it appears that even though the docker engine is running Windows containers, the local Kubernetes cluster (control plane) is running Linux.

I would greatly appreciate any ideas on how to fix the above error ie pull access denied so that I can run a local Kubernetes cluster on Windows 10 with Windows containers.

The error you are seeing is not related to whether it can run or cannot run Windows containers, it's because it's not able to pull the image. It doesn't look like you pushed the image to docker hub . After you build it you need to run:

docker tag -t <yourdockerhubuser>/iis iis
docker push <yourdockerhubuser>/iis

You will need to set up your docker hub credentials as an ImagePullSecrets on your deployment. Then on you K8s deployment:

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>

Ok, this container will not run because you have Linux on your node, so you need to have a Windows node and for that, you will have set up the kubelet on your Windows machine. (I believe Docker for Windows doesn't support a Windows kubelet, and just a Linux kubelet running in VM).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM