模棱两可的警告:"WARN[0064] image [gcr.io/wired-benefit-XXXXX/demoapp] is not used by the deployment"

Ambiguous warning : "WARN[0064] image [gcr.io/wired-benefit-XXXXX/demoapp] is not used by the deployment"

预期行为

不应显示声明的警告。

实际行为

每次我进行更改并触发重新部署时,我都会收到如下错误:

WARN[0064] image [gcr.io/wired-benefit-XXXXX/demoapp] is not used by the deployment

但是图像已用更新的更改进行了修改,所以我不确定错误指示的是什么,

信息

apiVersion: skaffold/v2beta8
kind: Config
metadata:
  name: demoapp
build:
  artifacts:
  - image: gcr.io/wired-benefit-293406/demoapp
deploy:
  kubectl:
    manifests:
    - k8*.yml

K8s 清单内容:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: demoapp
  name: demoapp
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demoapp
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: demoapp
    spec:
      containers:
      - image: gcr.io/wired-benefit-293406/demoapp
        imagePullPolicy: IfNotPresent
        name: demoapp
      restartPolicy: Always

apiVersion: v1
kind: Service
metadata:
  labels:
    app: demoapp
  name: demoapp-svc
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 3000
  selector:
    app: demoapp
  type: LoadBalancer

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: demoapp
spec:
  maxReplicas: 5
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: demoapp
  targetCPUUtilizationPercentage: 80

重现该行为的步骤

  1. 一个非常基本的入门演示应用程序
  2. skaffold dev
  3. 任何更改...docker 通过 skaffold 构建成功,甚至推送到注册表

但是,更改没有反映出来。可能是标签相关的问题。当我为部署手动将映像名称设置为最新时,应用程序更改就起作用了。

正如我在评论中所说:

Does your K8S manifests is a single file with Deployment, Service and HPA inside of it? I ran exactly as you've pasted it (encountered same warning) and it lacked the --- in between the resources.

具体来说 Content of K8s manifests 中包含的内容,此文件缺少资源之间的三个破折号 (---)

可以通过以下方式解决:

  • 在多个文件中拆分资源(通过遵循 skaffold.yaml 及其模板 k8*.yml):
    • k8s-deployment.yaml
    • k8s-service.yaml
    • k8s-hpa.yaml
  • Content of K8s manifests 中的每个资源之间添加 ---(示例):
DEPLOYMENT
---
SERVICE
--- 
HPA

您可以按照以下 Whosebug 答案在 YAML 文件中阅读有关 --- 的更多信息:


至于复现。我用的是官方的入门指南:

我把Content of K8s manifests复制到k8s-pod.yaml里面,改了行(这个文件资源之间没有---):

      - image: gcr.io/PROJECT-NAME/demoapp

运行 下面的命令为:

  • $ skaffold dev
Listing files to watch...
 - gcr.io/PROJECT-NAME/demoapp
Generating tags...
 - gcr.io/PROJECT-NAME/demoapp -> gcr.io/PROJECT-NAME/demoapp:<--REDACTED-->
Checking cache...
 - gcr.io/PROJECT-NAME/demoapp: Not found. Building
Building [gcr.io/PROJECT-NAME/demoapp]...
Sending build context to Docker daemon  3.072kB
<--REDACTED-->
<--REDACTED-->: Pushed 
<--REDACTED-->: Layer already exists 
<--REDACTED-->: digest: <--REDACTED--> size: 739
Tags used in deployment:
 - gcr.io/PROJECT-NAME/demoapp -> gcr.io/PROJECT-NAME/demoapp:<--REDACTED-->
Starting deploy...
WARN[0023] image [gcr.io/PROJECT-NAME/demoapp] is not used by the deployment 
 - horizontalpodautoscaler.autoscaling/demoapp created
Waiting for deployments to stabilize...
Deployments stabilized in 198.216977ms
Press Ctrl+C to exit
Watching for changes...

专注于:

WARN[0023] image [gcr.io/PROJECT-NAME/demoapp] is not used by the deployment 
 - horizontalpodautoscaler.autoscaling/demoapp created

如您所见,仅创建了 HPA 对象。 DeploymentService 未创建。它也显示与您相同的警告。

Running $ kubectl apply -f k8s-pod.yaml will yield the same results!

再次编辑 k8s-pod.yaml 文件以包含 --- 和 运行 $ skaffold dev 应该会产生类似于以下的输出:

Listing files to watch...
 - gcr.io/PROJECT-NAME/demoapp
Generating tags...
 - gcr.io/PROJECT-NAME/demoapp -> gcr.io/PROJECT-NAME/<--REDACTED-->
Checking cache...
 - gcr.io/PROJECT-NAME/demoapp: Not found. Building
<--REDACTED-->
<--REDACTED-->: Pushed 
<--REDACTED-->: Layer already exists 
<--REDACTED-->: digest: <--REDACTED--> size: 739
Tags used in deployment:
 - gcr.io/PROJECT-NAME/demoapp -> gcr.io/PROJECT-NAME/demoapp:<--REDACTED-->
Starting deploy...
 - deployment.apps/demoapp created
 - service/demoapp-svc created
 - horizontalpodautoscaler.autoscaling/demoapp created
Waiting for deployments to stabilize...
 - deployment/demoapp is ready.
Deployments stabilized in 5.450197785s
Press Ctrl+C to exit
Watching for changes...
[demoapp] Hello World with ---!
[demoapp] Hello World with ---!
[demoapp] Hello World with ---!

正如您在上面看到的,所有资源都已创建,没有关于部署未使用图像的警告,应用程序也有响应。


其他资源: