尝试创建Kubernetes部署,但显示0个可用容器

时间:2018-07-02 16:04:59

标签: kubernetes kubectl

我是k8的新手,所以我的某些术语可能不正确。但基本上,我正在尝试部署一个简单的Web api:在n个pod前面有一个负载均衡器(现在,n = 1)。

但是,当我尝试访问负载平衡器的IP地址时,它没有显示我的Web应用程序。当我运行kubectl get部署时,我得到了:

NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
tl-api    1         1         1            0           4m

这是我的YAML文件。让我知道是否有什么情况–我对此很陌生!

---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: tl-api
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: tl-api
    spec:
      containers:
      - name: tl-api
        image: tlk8s.azurecr.io/devicecloudwebapi:v1
        ports:
        - containerPort: 80
      imagePullSecrets:
      - name: acr-auth
      nodeSelector:
        beta.kubernetes.io/os: windows
---
apiVersion: v1
kind: Service
metadata:
  name: tl-api
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: tl-api

编辑2:当我尝试使用ACS(支持Windows)时,我得到了:

Events:
  Type     Reason                 Age                From                   Message
  ----     ------                 ----               ----                   -------
  Normal   Scheduled              11m                default-scheduler      Successfully assigned tl-api-3466491809-vd5kg to dc9ebacs9000
  Normal   SuccessfulMountVolume  11m                kubelet, dc9ebacs9000  MountVolume.SetUp succeeded for volume "default-token-v3wz9"
  Normal   Pulling                4m (x6 over 10m)   kubelet, dc9ebacs9000  pulling image "tlk8s.azurecr.io/devicecloudwebapi:v1"
  Warning  FailedSync             1s (x50 over 10m)  kubelet, dc9ebacs9000  Error syncing pod
  Normal   BackOff                1s (x44 over 10m)  kubelet, dc9ebacs9000  Back-off pulling image "tlk8s.azurecr.io/devicecloudwebapi:v1"

然后我尝试检查失败的Pod:

PS C:\users\<me>\source\repos\DeviceCloud\DeviceCloud\1- Presentation\DeviceCloud.Web.API> kubectl logs tl-api-3466491809-vd5kg
Error from server (BadRequest): container "tl-api" in pod "tl-api-3466491809-vd5kg" is waiting to start: trying and failing to pull image

运行docker images时,我看到以下内容:

REPOSITORY                                   TAG                            IMAGE ID            CREATED             SIZE
devicecloudwebapi                            latest                         ee3d9c3e231d        24 hours ago        7.85GB
tlk8s.azurecr.io/devicecloudwebapi           v1                             ee3d9c3e231d        24 hours ago        7.85GB
devicecloudwebapi                            dev                            bb33ab221910        25 hours ago        7.76GB

1 个答案:

答案 0 :(得分:2)

您的问题是容器映像tlk8s.azurecr.io/devicecloudwebapi:v1在私有容器注册表中。请查看以下命令底部的事件:

$ kubectl describe po -l=app=tl-api

Kubernetes官方文档描述了如何解决此问题,请参阅Pull an Image from a Private Registry,本质上是:

  • 创建一个秘密kubectl create secret docker-registry
  • spec.imagePullSecrets键下在部署中使用它