K8S创建Deployment,StatefulSet报错:missing required field "selector" in io.k8s.api.apps.v1.StatefulSetSpec; if you choose to ignore these errors, turn validation off with --validate=false

部分yaml脚本在修改了修改 apiVersion 选项: apps/v1版本之后之后报错

示例:apiVersion: apps/v1beta1 改成 apiVersion: apps/v1

报错信息:

[root@k8s-master rabbitmq-cluster-on-k8s]# kubectl apply -f rabbitmq_statefulsets.yaml 
service/rabbitmq created
configmap/rabbitmq-config created
error: unable to recognize "rabbitmq_statefulsets.yaml": no matches for kind "StatefulSet" in version "apps/v1beta1"
[root@k8s-master rabbitmq-cluster-on-k8s]# vi rabbitmq_statefulsets.yaml 
[root@k8s-master rabbitmq-cluster-on-k8s]# kubectl apply -f rabbitmq_statefulsets.yaml 
service/rabbitmq unchanged
configmap/rabbitmq-config unchanged
error: error validating "rabbitmq_statefulsets.yaml": error validating data: ValidationError(StatefulSet.spec): missing required field "selector" in io.k8s.api.apps.v1.StatefulSetSpec; if you choose to ignore these errors, turn validation off with --validate=false

处理方法:
yaml 增加选择器

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: rabbitmq
#  namespace: test-rabbitmq
spec:
  serviceName: rabbitmq
  selector:
    matchLabels:
      app: rabbitmq
  replicas: 3

效果:

posted @ 2021-07-01 14:55  一毛丶丶  阅读(2766)  评论(0编辑  收藏  举报