ValidationError:缺少必填字段“选择器"在io.k8s.api.v1.DeploymentSpec中 [英] ValidationError: missing required field "selector" in io.k8s.api.v1.DeploymentSpec

查看:410
本文介绍了ValidationError:缺少必填字段“选择器"在io.k8s.api.v1.DeploymentSpec中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了Hyper-V机器,并尝试使用Sawtooth YAML文件在Minikube上部署Sawtooth:

  ---apiVersion:v1种类:清单项目:-apiVersion:apps/v1种类:部署元数据:名称:锯齿-0规格:复制品:1选择器:matchLabels:名称:锯齿-0模板:元数据:标签:名称:锯齿-0规格:容器:-名称:sawtooth-devmode-engine图像:hyperledger/sawtooth-devmode-engine-rust:chime命令:-重击args:- -C-"devmode-engine-rust -C tcp://$ HOSTNAME:5050"-名称:sawtooth-settings-tp图像:hyperledger/sawtooth-settings-tp:chime命令:-重击args:- -C-"settings-tp -vv -C tcp://$ HOSTNAME:4004"-名称:sawtooth-intkey-tp-python图像:hyperledger/sawtooth-intkey-tp-python:chime命令:-重击args:- -C-"intkey-tp-python -vv -C tcp://$ HOSTNAME:4004"-名称:sawtooth-xo-tp-python图片:hyperledger/sawtooth-xo-tp-python:chime命令:-重击args:- -C-"xo-tp-python -vv -C tcp://$ HOSTNAME:4004"-名称:锯齿验证器图像:hyperledger/sawtooth-validator:chime端口:-名称:tpcontainerPort:4004-名称:共识containerPort:5050-名称:验证者containerPort:8800命令:-重击args:- -C-《 sawadm keygen》&&锯齿锁原my_key \&&锯齿生成-k/root/.sawtooth/keys/my_key.priv \&&锯齿提案创建\-k/root/.sawtooth/keys/my_key.priv \sawtooth.consensus.algorithm.name = Devmode \sawtooth.consensus.algorithm.version = 0.1 \-o config.batch \&&sawadm创世纪config-genesis.batch config.batch \&&锯齿验证器-vv--endpoint tcp://$ SAWTOOTH_0_SERVICE_HOST:8800 \--bind组件:tcp://eth0:4004 \--bind共识:tcp://eth0:5050 \--bind network:tcp://eth0:8800-名称:sawtooth-rest-api图像:hyperledger/sawtooth-rest-api:chime端口:-名称:apicontainerPort:8008命令:-重击args:- -C-"sawtooth-rest-api -C tcp://$ HOSTNAME:4004"-名称:锯齿壳图像:hyperledger/锯齿壳:铃命令:-重击args:- -C-锯齿键控&&尾-f/dev/null"-apiVersion:apps/v1种类:服务元数据:名称:锯齿-0规格:类型:ClusterIP选择器:名称:锯齿-0端口:-名称:"4004"协议:TCP端口:4004targetPort:4004-名称:"5050"协议:TCP端口:5050targetPort:5050-名称:"8008"协议:TCP端口:8008targetPort:8008-名称:"8800"协议:TCP端口:8800targetPort:8800 

解决方案

您需要修复部署 yaml 文件.从错误消息中可以看到, Deployment.spec.selector 字段不能为空.

更新 yaml (即添加 spec.selector ),如下所示:

 规范:复制品:1选择器:matchLabels:app.kubernetes.io/名称:sawtooth-0模板:元数据:标签:app.kubernetes.io/名称:sawtooth-0 

  • 为什么 selector 字段很重要?

选择器字段定义部署如何查找要管理的Pod.在这种情况下,您只需选择在Pod模板中定义的标签( app.kubernetes.io/name:sawtooth-0 ).但是,只要Pod模板本身满足该规则,就可以使用更复杂的选择规则.

更新:

k8s服务的 apiVersion v1 :

 <代码>-apiVersion:v1#在此处更新种类:服务元数据:app.kubernetes.io/名称:sawtooth-0规格:类型:ClusterIP选择器:app.kubernetes.io/名称:sawtooth-0…… 

I've created Hyper-V machine and tried to deploy Sawtooth on Minikube using Sawtooth YAML file : https://sawtooth.hyperledger.org/docs/core/nightly/master/app_developers_guide/sawtooth-kubernetes-default.yaml

I changed the apiVersion i.e. apiVersion: extensions/v1beta1 to apiVersion: apps/v1, though I have launched Minikube in Kubernetes v1.17.0 using this command

minikube start --kubernetes-version v1.17.0

After that I can't deploy the server. Command is

kubectl apply -f sawtooth-kubernetes-default.yaml --validate=false

It shows an error with "sawtooth-0" is invalid.

---
apiVersion: v1
kind: List

items:

- apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: sawtooth-0
  spec:
    replicas: 1
    selector:
      matchLabels:
        name: sawtooth-0
    template:
      metadata:
        labels:
          name: sawtooth-0
      spec:
        containers:
          - name: sawtooth-devmode-engine
            image: hyperledger/sawtooth-devmode-engine-rust:chime
            command:
              - bash
            args:
              - -c
              - "devmode-engine-rust -C tcp://$HOSTNAME:5050"

          - name: sawtooth-settings-tp
            image: hyperledger/sawtooth-settings-tp:chime
            command:
              - bash
            args:
              - -c
              - "settings-tp -vv -C tcp://$HOSTNAME:4004"

          - name: sawtooth-intkey-tp-python
            image: hyperledger/sawtooth-intkey-tp-python:chime
            command:
              - bash
            args:
              - -c
              - "intkey-tp-python -vv -C tcp://$HOSTNAME:4004"

          - name: sawtooth-xo-tp-python
            image: hyperledger/sawtooth-xo-tp-python:chime
            command:
              - bash
            args:
              - -c
              - "xo-tp-python -vv -C tcp://$HOSTNAME:4004"

          - name: sawtooth-validator
            image: hyperledger/sawtooth-validator:chime
            ports:
              - name: tp
                containerPort: 4004
              - name: consensus
                containerPort: 5050
              - name: validators
                containerPort: 8800
            command:
              - bash
            args:
              - -c
              - "sawadm keygen \
              && sawtooth keygen my_key \
              && sawset genesis -k /root/.sawtooth/keys/my_key.priv \
              && sawset proposal create \
                -k /root/.sawtooth/keys/my_key.priv \
                sawtooth.consensus.algorithm.name=Devmode \
                sawtooth.consensus.algorithm.version=0.1 \
                -o config.batch \
              && sawadm genesis config-genesis.batch config.batch \
              && sawtooth-validator -vv \
                  --endpoint tcp://$SAWTOOTH_0_SERVICE_HOST:8800 \
                  --bind component:tcp://eth0:4004 \
                  --bind consensus:tcp://eth0:5050 \
                  --bind network:tcp://eth0:8800"

          - name: sawtooth-rest-api
            image: hyperledger/sawtooth-rest-api:chime
            ports:
              - name: api
                containerPort: 8008
            command:
              - bash
            args:
              - -c
              - "sawtooth-rest-api -C tcp://$HOSTNAME:4004"

          - name: sawtooth-shell
            image: hyperledger/sawtooth-shell:chime
            command:
              - bash
            args:
              - -c
              - "sawtooth keygen && tail -f /dev/null"

- apiVersion: apps/v1
  kind: Service
  metadata:
    name: sawtooth-0
  spec:
    type: ClusterIP
    selector:
      name: sawtooth-0
    ports:
      - name: "4004"
        protocol: TCP
        port: 4004
        targetPort: 4004
      - name: "5050"
        protocol: TCP
        port: 5050
        targetPort: 5050
      - name: "8008"
        protocol: TCP
        port: 8008
        targetPort: 8008
      - name: "8800"
        protocol: TCP
        port: 8800
        targetPort: 8800

解决方案

You need to fix your deployment yaml file. As you can see from your error message, the Deployment.spec.selector field can't be empty.

Update the yaml (i.e. add spec.selector) as shown in below:

  spec:
    replicas: 1
    selector:
      matchLabels:
        app.kubernetes.io/name: sawtooth-0
    template:
      metadata:
        labels:
          app.kubernetes.io/name: sawtooth-0

  • Why selector field is important?

The selector field defines how the Deployment finds which Pods to manage. In this case, you simply select a label that is defined in the Pod template (app.kubernetes.io/name: sawtooth-0). However, more sophisticated selection rules are possible, as long as the Pod template itself satisfies the rule.

Update:

The apiVersion for k8s service is v1:

- apiVersion: v1 # Update here
  kind: Service
  metadata:
    app.kubernetes.io/name: sawtooth-0
  spec:
    type: ClusterIP
    selector:
      app.kubernetes.io/name: sawtooth-0
    ... ... ...

这篇关于ValidationError:缺少必填字段“选择器"在io.k8s.api.v1.DeploymentSpec中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆