【问题标题】:I am getting this specific error of error when creating ".\\deployment_test.yaml": Deployment in version "v1" cannot be handled as a Deployment创建“.\\deployment_test.yaml”时出现此特定错误错误:版本“v1”中的部署无法作为部署处理
【发布时间】:2022-01-12 10:28:49
【问题描述】:

我正在尝试使用 kubernetes 中的 yaml 文件创建部署,但遇到此特定错误:

服务器出错(BadRequest):创建“.\deployment_test.yaml”时出错:版本“v1”中的部署无法作为部署处理:v1.Deployment.Spec:v1.DeploymentSpec.Template:v1 .PodTemplateSpec.ObjectMeta: v1.ObjectMeta.Labels: ReadMapCB: expect { or n, but found ", error found in #10 byte of ...|"labels":"test"},"sp|...强>

我的yaml文件如下:

kind: Deployment
metadata:
    labels:
      environment: test
    name: agentstubpod-deployment
spec:
  replicas: 3
  selector: 
    matchLabels: 
      enviroment: test
  minReadySeconds: 10
  strategy: 
    rollingUpdate: 
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template: 
    metadata:
      labels: test
    spec: 
      containers:
      - name: agentstub
        image: some-repo:latest 
---
apiVersion: apps/v1
kind: Deployment
metadata:
    labels:
      environment: test
    name: proxystubpod-deployment
spec:
  replicas: 3
  selector: 
    matchLabels: 
      enviroment: test
  minReadySeconds: 10
  strategy: 
    rollingUpdate: 
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template: 
    metadata:
      labels: test
    spec: 
      containers:
      - name: procyservice
        image: some-repo:latest

这个语法有什么问题?我很难进行部署

【问题讨论】:

    标签: kubernetes yaml


    【解决方案1】:

    有一些错误配置。

    1. 第一次部署中缺少 apiVersion
    2. metadata 下方的缩进不正确
    3. 您必须包含metadata.name 字段
    4. spec.selector.matchLabelsspec.template.metadata.labels 应该匹配。

    以下是更正后的示例:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        environment: test
        name: agentstubpod-deployment
      name: dep1
    spec:
      replicas: 3
      selector:
        matchLabels:
          environment: test
      minReadySeconds: 10
      strategy:
        rollingUpdate:
          maxSurge: 1
          maxUnavailable: 0
        type: RollingUpdate
      template:
        metadata:
          labels:
            environment: test
        spec:
          containers:
          - name: agentstub
            image: some-repo:latest
    
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        environment: test
        name: proxystubpod-deployment
      name: dep2
    spec:
      replicas: 3
      selector:
        matchLabels:
          environment: test
      minReadySeconds: 10
      strategy:
        rollingUpdate:
          maxSurge: 1
          maxUnavailable: 0
        type: RollingUpdate
      template:
        metadata:
          labels:
            environment: test
        spec:
          containers:
          - name: procyservice
            image: some-repo:latest
    

    【讨论】:

      猜你喜欢
      • 2019-12-05
      • 2020-02-14
      • 2021-09-15
      • 2017-06-05
      • 2022-01-09
      • 2023-01-16
      • 2015-04-29
      • 2018-12-07
      • 1970-01-01
      相关资源
      最近更新 更多