【发布时间】:2022-01-19 22:31:43
【问题描述】:
我收到此错误消息:
Deployment.apps "nginxapp" is invalid: spec.template.spec.containers[0].volumeMounts[0].name: Not found: "nginx-claim"
现在,我认为部署要求使用持久存储,所以这些是我按顺序运行的 det 文件:
首先,将卷持久化到 /data,因为它在 minikube (https://minikube.sigs.k8s.io/docs/handbook/persistent_volumes/) 上持久化:
apiVersion: v1
kind: PersistentVolume
metadata:
name: small-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /data
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- my-node
然后,对于我的 nginx 部署,我提出了一个声明:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nginx-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
在服务之前我运行部署,这是给我上面的错误,看起来像这样:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginxapp
name: nginxapp
spec:
replicas: 1
volumes:
- persistentVolumeClaim:
claimName: nginx-claim
selector:
matchLabels:
app: nginxapp
template:
metadata:
labels:
app: nginxapp
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
volumeMounts:
- mountPath: "/data/www"
name: nginx-claim
-
我哪里做错了?不是部署 -> 卷声明 -> 卷吗?
-
我做得对吗?持久卷是 pod 范围的 (?),因此通常被命名。但索赔是每次部署?所以这就是为什么我把它命名为
nginx-claim。我可能在这里弄错了,但不应该让这个简单的运行 doh 出错。 -
在我的部署中,我设置了
mountPath: "/data/www",这应该遵循已在持久卷定义中设置的目录,还是在此基础上构建?所以就我而言,我得到/data/data/www?
【问题讨论】:
标签: kubernetes minikube