我要在一个持久卷声明中将多个volumeMount附加到minikube中的部署。
我有一个部署了tomcat的应用程序,它需要保留三个不同的文件夹(/ var / log / app,/ var / lib / app,/ etc / app)。 当容器启动时,我应该在每个目录中获取文件,但是只会填充日志,并且应用程序将失败。 知道我的Yaml是正确的还是以错误的方式进行处理?
K8s yaml:
import perfplot
perfplot.show(
setup=lambda n: pd.DataFrame({'A': np.random.choice(n//10, n), 'B': np.ones(n)}),
kernels=[
lambda df: df.groupby('A')['B'].transform('sum'),
lambda df: df.A.map(df.groupby('A')['B'].sum()),
],
labels=['GroupBy.transform', 'GroupBy.sum + map'],
n_range=[2**k for k in range(5, 20)],
xlabel='N',
logy=True,
logx=True
)
v2:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-volume
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 6Gi
hostPath:
path: /data/pv-volume
storageClassName: manual
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: manual
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
labels:
app: app
spec:
selector:
matchLabels:
app: app
replicas: 1
strategy: {}
template:
metadata:
labels:
app: app
spec:
containers:
- image: app:latest
name: app
env:
- name: JAVA_OPTS
value: -Xms64M -Xmx512M
ports:
- containerPort: 8080
resources:
requests:
memory: "512Mi"
cpu: "250m"
limits:
memory: "1024Mi"
cpu: "500m"
volumeMounts:
- name: pv-storage1
mountPath: /var/log/app
subPath: log
- name: pv-storage1
mountPath: /var/lib/app
subPath: lib
- name: pv-storage1
mountPath: /etc/app
subPath: etc
tty: true
volumes:
- name: pv-storage1
persistentVolumeClaim:
claimName: pv-claim
restartPolicy: Always
status: {}
答案 0 :(得分:0)
使用上面的配置,您尝试将一个PV挂载到多个目录,这意味着它们将与PV配置上的主机路径携带相同的数据。
如果要使用具有不同内容的多个不同目录,则需要为每个目录创建PV和PVC,如下所示:
kind: PersistentVolume
metadata:
name: pv-volume-log
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 6Gi
hostPath:
path: /data/pv-volume/log
storageClassName: manual
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-claim-log
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: manual
---
kind: PersistentVolume
metadata:
name: pv-volume-lib
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 6Gi
hostPath:
path: /data/pv-volume/lib
storageClassName: manual
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-claim-lib
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: manual
---
kind: PersistentVolume
metadata:
name: pv-volume-etc
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 6Gi
hostPath:
path: /data/pv-volume/etc
storageClassName: manual
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-claim-etc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: manual
然后在您的Deployment yaml中添加这些卷并将卷分别附加到mountPath:
...
volumes:
- name: pv-storage-log
persistentVolumeClaim:
claimName: pv-claim-log
- name: pv-storage-lib
persistentVolumeClaim:
claimName: pv-claim-lib
- name: pv-storage-etc
persistentVolumeClaim:
claimName: pv-claim-etc
restartPolicy: Always
...
我希望它将对您有用