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

Slo*_*rio 5 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
Run Code Online (Sandbox Code Playgroud)

这是我的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
Run Code Online (Sandbox Code Playgroud)

编辑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"
Run Code Online (Sandbox Code Playgroud)

然后,我尝试检查失败的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
Run Code Online (Sandbox Code Playgroud)

运行时,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
Run Code Online (Sandbox Code Playgroud)

Mic*_*las 7

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

$ kubectl describe po -l=app=tl-api
Run Code Online (Sandbox Code Playgroud)

Kubernetes 官方文档描述了如何解决此问题,请参阅从私有注册表中提取映像,本质上:

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

  • 啊,我的 Google fu 失败了。谢谢你的发现。看来我目前无法在 AKS 上运行 Windows 容器!谢谢你的帮助。(出于好奇,它说:“要运行 Windows Server 容器,您需要运行基于 Windows Server 的节点。此时 AKS 中不提供基于 Windows Server 的节点。如果您需要在 Kubernetes 上运行 Windows Server 容器Azure,请参阅 acs-engine 的文档。”) (2认同)