Kubernetes and mongo, PV, PVC



嗨,只是一个小问题。我设法(?(在mongo DB上实施PV和PVC。我使用PV作为本地,而不是在云上。容器重新启动后,当k8s在我的电脑上运行时,有办法保存数据吗?

我不确定我是否做对了,但我需要的是在他重新启动后保存mongo数据。最好的方法是什么?(无mongo图集(

更新:我设法使票务服务数据库工作得很好,但我有两个其他服务,它就是不起作用!我更新了yaml文件,这样你就可以看到当前的状态。auth mongo和tickets mongo一样,为什么它不起作用

机票depl mongo yaml文件:

apiVersion: apps/v1
kind: Deployment
metadata:
name: tickets-mongo-depl
spec:
replicas: 1
selector:
matchLabels:
app: tickets-mongo
template:
metadata:
labels:
app: tickets-mongo
spec:
containers:
- name: tickets-mongo
image: mongo
args: ["--dbpath", "data/auth"]
livenessProbe:
exec:
command:
- mongo
- --disableImplicitSessions
- --eval
- "db.adminCommand('ping')"
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 6
volumeMounts:
- mountPath: /data/auth
name: tickets-data
volumes:
- name: tickets-data
persistentVolumeClaim:
claimName: tickets-pvc
---
apiVersion: v1
kind: Service
metadata:
name: tickets-mongo-srv
spec:
selector:
app: tickets-mongo
ports:
- name: db
protocol: TCP
port: 27017
targetPort: 27017

auth-mongo-depl.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-mongo-depl
spec:
replicas: 1
selector:
matchLabels:
app: auth-mongo
template:
metadata:
labels:
app: auth-mongo
spec:
containers:
- name: auth-mongo
image: mongo
args: ["--dbpath", "data/db"]
livenessProbe:
exec:
command:
- mongo
- --disableImplicitSessions
- --eval
- "db.adminCommand('ping')"
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 6
volumeMounts:
- mountPath: /data/db
name: auth-data
volumes:
- name: auth-data
persistentVolumeClaim:
claimName: auth-pvc
---
apiVersion: v1
kind: Service
metadata:
name: auth-mongo-srv
spec:
selector:
app: auth-mongo
ports:
- name: db
protocol: TCP
port: 27017
targetPort: 27017

NAME         CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                 STORAGECLASS   REASON   AGE
pv-auth      1Gi        RWO            Retain           Bound    default/auth-pvc      auth                    78m
pv-orders    1Gi        RWO            Retain           Bound    default/orders-pvc    orders                  78m
pv-tickets   1Gi        RWO            Retain           Bound    default/tickets-pvc   tickets                 78m

我将mongo容器与票证、订单和身份验证服务一起使用。只是添加一些信息以使其清楚。

NAME                                     READY   STATUS    RESTARTS   AGE
auth-depl-66c5d54988-ffhwc               1/1     Running   0          36m
auth-mongo-depl-594b98fcc5-k9hj8         1/1     Running   0          36m
client-depl-787cf6c7c6-xxks9             1/1     Running   0          36m
expiration-depl-864d846445-b95sh         1/1     Running   0          36m
expiration-redis-depl-64bd9fdb95-sg7fc   1/1     Running   0          36m
nats-depl-7d6c7dc46-m6mcg                1/1     Running   0          36m
orders-depl-5478cf4dfd-zmngj             1/1     Running   0          36m
orders-mongo-depl-5f974847d7-bz9s4       1/1     Running   0          36m
payments-depl-78f85d94fd-4zs55           1/1     Running   0          36m
payments-mongo-depl-5d5c47494b-7zjrl     1/1     Running   0          36m
tickets-depl-84d59fd47c-cs4k5            1/1     Running   0          36m
tickets-mongo-depl-66798d9874-cfbqb      1/1     Running   0          36m

pv:的示例

apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-tickets
labels:
type: local
spec:
storageClassName: tickets
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/tmp"

我所要做的就是更改每个PV中hostPath的路径。相同的路径将使应用程序失败。

pv1:

hostPath:
path: "/path/x1"

pv2:

hostPath:
path: "/path/x2"

就像…只是不一样。

相关内容

  • 没有找到相关文章