K8s mongoldb yaml
时间: 2024-02-10 13:07:41 浏览: 141
k8s-yaml:k8s-yaml
以下是一个K8s部署MongoDB的YAML示例:
```yaml
apiVersion: v1
kind: Service
metadata:
name: mongodb
labels:
app: mongodb
spec:
ports:
- port: 27017
targetPort: 27017
selector:
app: mongodb
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mongodb
spec:
serviceName: mongodb
replicas: 3
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo
ports:
- containerPort: 27017
volumeMounts:
- name: mongodb-data
mountPath: /data/db
volumeClaimTemplates:
- metadata:
name: mongodb-data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
```
该YAML文件定义了一个名为mongodb的Service和StatefulSet,其中StatefulSet包含3个MongoDB实例。每个实例都有一个1GB的持久卷,用于存储数据。
阅读全文