创建“.\\deployment_test.yaml”时出现此特定错误:版本 "v1" 中的部署无法作为部署处理

I am getting this specific error of error when creating ".\\deployment_test.yaml": Deployment in version "v1" cannot be handled as a Deployment

我正在尝试使用 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

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

有些配置错误。

  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