0

预期行为

不应显示声明的警告。

实际行为

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

WARN[0064] image [gcr.io/wired-benefit-XXXXX/demoapp] 没有被部署使用

然而,图像已通过更新的更改进行了修改,所以我不确定错误表示什么,

信息

  • Skaffold版本:版本... v1.15.0
  • 操作系统:... MacOS Catilina 10.15.16
  • skaffold.yaml 的内容:
apiVersion: skaffold/v2beta8
kind: Config
metadata:
  name: demoapp
build:
  artifacts:
  - image: gcr.io/wired-benefit-293406/demoapp
deploy:
  kubectl:
    manifests:
    - k8*.yml

K8s manifest 的内容:

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 build 通过 skaffold 甚至推送到注册表成功

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

4

1 回答 1

1

正如我在评论中所说:

K8S manifests是一个文件DeploymentService里面HPA有 , 吗?我完全按照您粘贴的方式运行(遇到相同的警告),并且它缺少---资源之间的内容。

具体来说,该文件在资源之间Content of K8s manifests缺少三个破折号。(---)

它可以通过以下方式修复:

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

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


至于繁殖。我使用了官方的入门指南:

我将其复制Content of K8s manifestsk8s-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创建了对象。Deployment并且Service没有被创建。它也显示与您相同的警告。

运行$ kubectl apply -f k8s-pod.yaml将产生相同的结果!

编辑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 ---!

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


其他资源:

于 2020-10-27T13:16:44.193 回答