服务器错误(BadRequest):创建“pod.yaml”时出错:

时间:2018-02-15 13:51:27

标签: kubernetes kubectl

运行

时出现以下错误
kubectl create -f pod.yaml

错误

Error from server (BadRequest): error when creating "pod.yaml": Pod in 
version "ratings:v1" cannot be handled as a Pod: no kind "Pod" is 
registered for version "ratings:v1"

minikube启动并运行,我甚至尝试将其更改为kind: Deployment,但我又收到了一条错误消息:

error: unable to recognize "pod.yaml": no matches for /, Kind=Deployment

YAML:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: customer-ratings
  labels:
    app: product-ratings-vue
spec:
  replicas: 1
  selector:
    matchLabels:
      app: product-ratings-vue
  template:
    metadata:
      labels:
        app: product-ratings-vue 
    spec:
      containers: 
      - name: api-service
        image: api-service
        ports:
          - containerPort: 8080
          - containerPort: 8000
        resources: {}
        volumeMounts:
          - mountPath: /usr/local/tomcat/logs
            name: api-service-claim 

# ekomi-import       
      - name: ekomi-import
        image: ekomi-import
        resources: {}

# cache
      - name: cache
        image: cache
        resources:
          limits:
            memory: "536870912"

# storage
      - name: storage
        image: storage
        ports:
         - containerPort: 7000
         - containerPort: 7001
         - containerPort: 7199
         - containerPort: 9042
         - containerPort: 9160
        resources: {}
# view
      - name: view
        image: view
        ports:
         - containerPort: 3000
        resources: {}

      volumes:
        - name: api-service-claim
          persistentVolumeClaim:
            claimName: api-service-claim
 # tomcat
      - name: tomcat
        image: tomcat
# node
      - name: node
        image: node
        resources: {}
# openJdk
      - name: node
      - image: node
        resources: {}

1 个答案:

答案 0 :(得分:4)

这里有很多问题。我已经描述了其中一些:

<强> 1 pod.yaml文件的结构是Deployment对象的结构。

<强> 2 apiVersion的{​​{1}}取决于kubernetes版本:

  • Deployment适用于1.8.0之前的版本
  • apps/v1beta1适用于从1.9.0之前的1.8.0开始的版本
  • apps/v1beta2适用于从1.9.0开始的版本

因此,如果您在最新的kubernetes群集上部署apps/v1,则应该从以下位置开始:

pod.yaml

第3 部分:

apiVersion: apps/v1
kind: Deployment

应更改为:

spec:
  replicas: 1
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 100Mi
  template:
    metadata:
      labels: 
        app: product-ratings-vue

<强> 4 第二个spec: replicas: 1 template: metadata: labels: app: product-ratings-vue 块应移至与spec相同的级别:

spec.template.metadata

最终 spec: replicas: 1 template: metadata: labels: app: product-ratings-vue spec: containers: 是:

deployment.yaml