尝试创建 Kubernetes 部署但它显示 0 pods 可用

Trying to create a Kubernetes deployment but it shows 0 pods available

我是 k8s 的新手,所以我的一些术语可能不适用。但基本上,我正在尝试部署一个简单的网络 api:在 n pods 前面的一个负载均衡器(现在,n=1)。

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

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

您的问题是容器映像 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 键下