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

8yparm6h  于 2022-12-17  发布在  Kubernetes
关注(0)|答案(1)|浏览(586)

运行时出现以下错误

kubectl create -f pod.yaml

误差

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

minikube已经启动并运行,我甚至尝试将其更改为kind: Deployment,但我得到了另一个错误,说:

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

亚姆勒:

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

# import       
      - name: applicant-import
        image: applicant-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: applicant-claim
          persistentVolumeClaim:
            claimName: applicant-claim
 # tomcat
      - name: tomcat
        image: tomcat
# node
      - name: node
        image: node
        resources: {}
# openJdk
      - name: node
      - image: node
        resources: {}
7rfyedvj

7rfyedvj1#

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

1.pod.yaml文件的结构是Deployment对象的结构。
2.apiVersion适用于Deployment,取决于kubernetes版本:

  • apps/v1beta1(对于1.8.0之前的版本)
  • apps/v1beta2适用于1.8.0及1.9.0之前的版本
  • apps/v1(适用于1.9.0以上的版本)

因此,如果您在最新的kubernetes集群上部署pod.yaml,则应从以下位置启动:

apiVersion: apps/v1
kind: Deployment

**3.**零件:

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

应改为:

spec:
  replicas: 1
  template:
    metadata:
      labels: 
        app: product-ratings-vue

**4.**第二个spec块应在与spec.template.metadata相同的级别上移动:

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

最终的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: {}

 # tomcat
      - name: tomcat
        image: tomcat
# node
      - name: node
        image: node
        resources: {}
# openJdk
      - name: node
        image: node
        resources: {}

      volumes:
        - name: api-service-claim
          persistentVolumeClaim:
            claimName: api-service-claim

相关问题