Kubectl创建持久存储错误输出

时间:2018-01-31 14:50:06

标签: deployment kubernetes persistent-volumes

我正在尝试为沙发数据库部署持久性存储,但是它失败并出现错误

kubectl create -f couch_persistant_deploy.yaml

  

错误:验证错误" couch_persistant_deploy.yaml":验证数据时出错:找不到类型:v1.Deployment;如果您选择忽略这些错误,请使用--validate = false

关闭验证

创建volume.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /mnt/sda1/data/test

声明volume.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: task-pv-claim
  labels:
    app: couchdb
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

部署VM.yaml

apiVersion: extensions/v1beta1
#apiVersion: v1
kind: Deployment
#kind: ReplicationController
metadata:
  name: couchdb
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: couchdb
    spec:
      containers:
        - name: couchdb
          image: "couchdb"
          imagePullPolicy: Always
          env:
          - name: COUCHDB_USER
            value: admin
          - name: COUCHDB_PASSWORD
            value: password
          ports:
          - name: couchdb
            containerPort: 5984
          - name: epmd
            containerPort: 4369
            containerPort: 9100
          volumeMounts:
          - mountPath: "/opt/couchdb/data"
            name: task-pv-storage
      imagePullSecrets:
      - name: registrypullsecret2
      #volumes:
        #- name: database-storage
        #  emptyDir: {}
      volumes:
      - name: task-pv-storage
        persistentVolumeClaim:
        claimName: task-pv-claim

任何线索都非常感谢。

1 个答案:

答案 0 :(得分:3)

您的错误消息应如下所示:

  

错误:错误验证" couch_persistant_deploy.yaml":错误验证数据:ValidationError(Deployment.spec.template.spec.volumes [0]):unknown field" claimName"在io.k8s.api.core.v1.Volume;如果您选择忽略这些错误,请使用--validate = false

关闭验证

请参阅,错误消息是特定的:unknown field "claimName" in io.k8s.api.core.v1.Volume

您需要将claimName置于persistentVolumeClaim下。

  volumes:
  - name: task-pv-storage
    persistentVolumeClaim:
      claimName: task-pv-claim  # fix is here

但你确实

  volumes:
  - name: task-pv-storage
    persistentVolumeClaim:
    claimName: task-pv-claim  # invalid

这使您的部署对象无效