数据库
首页 > 数据库> > K8s部署MongoDB使用cephfs做数据持久化

K8s部署MongoDB使用cephfs做数据持久化

作者:互联网

1.1 前提准备

1.2 编写 yaml 文件

编写 mongo.yaml 文件,提供了一个对外暴露的 NodePort 类型的 Service,用于外部访问。

---
apiVersion: v1
kind: Namespace
metadata:
  name: mongodb
  labels:
    name: mongo
---
#创建fastdfs存储卷pvc分配1G使用
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mongodb-pvc
  namespace: mongodb
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: jyy-cephfs-sc
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
  name: mongo
  namespace: mongodb
  labels:
    app: mongo
spec:
  ports:
  - name: mongo
    port: 27017
    targetPort: 27017
  clusterIP: None
---
apiVersion: v1
kind: Service
metadata: 
  name: mongo-service
  namespace: mongodb
  labels: 
    app: mongo
spec: 
  ports: 
  - name: mongo-service
    port: 27017
    nodePort: 27017
  selector: 
    app: mongo
  type: NodePort
---
apiVersion: apps/v1
kind: StatefulSet
metadata: 
  name: mongo
  namespace: mongodb
spec: 
  selector: 
    matchLabels: 
      app: mongo
  serviceName: "mongo"
  replicas: 1
  template: 
    metadata: 
      labels: 
        app: mongo
    spec: 
      terminationGracePeriodSeconds: 0
      containers: 
      - name: mongo
        image: mongo:latest
        env:
          - name: MONGO_INITDB_ROOT_USERNAME
            value: root
          - name: MONGO_INITDB_ROOT_PASSWORD
            value: 'uUN38#%pq'
        command:  
        - mongod 
        - "--bind_ip_all"
        - "--replSet"
        - rs0
        ports: 
        - containerPort: 27017
        volumeMounts: 
        - name: mongo-data
          mountPath: /data/db
      volumes:
        - name: mongo-data
          persistentVolumeClaim:
            claimName: mongodb-pvc

标签:K8s,mongo,MongoDB,27017,metadata,mongodb,cephfs,app,name
来源: https://blog.csdn.net/m0_57480266/article/details/120553714