运行时出现以下错误
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
yaml:
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
# ekomi-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: {}
最佳答案
你这里有很多问题。我已经描述了其中一些:
1. pod.yaml
文件的结构是一个 Deployment
对象的结构。
2. apiVersion
的 Deployment
取决于 kubernetes 版本:
apps/v1beta1
apps/v1beta2
适用于 1.8.0 和 1.9.0 之前的版本 apps/v1
用于从 1.9.0 开始的版本 因此,如果您将
pod.yaml
部署在最新的 kubernetes 集群上,它应该从以下位置启动: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
关于kubernetes - 来自服务器的错误 (BadRequest) : error when creating "pod.yaml":,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48808887/