K3S笔记 安装MongoDB

YAML文件:

apiVersion: v1
kind: Namespace
metadata:
  name: mongo
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: mongo
  namespace: mongo
data:
  mongod.conf: |
    security: 
      authorization: enabled
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mongo-pvc
  namespace: mongo
  labels:
    app: mongo
spec:
  storageClassName: longhorn
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
---
apiVersion: v1
kind: Service
metadata:
  name: mongo
  namespace: mongo
spec:
  selector:
    app: mongo
  type: NodePort
  ports:
    - name: mongo
      protocol: TCP
      port: 27017
      targetPort: mongo
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo
  namespace: mongo
  labels:
    app: mongo
spec:
  selector:
    matchLabels:
      app: mongo
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mongo
    spec:
      containers:
        - name: mongo
          image: mongo
          command: ["mongod"]
          args: ["--bind_ip_all", "-f", "/etc/mongod/mongod.conf"]
          resources:
            requests:
              cpu: "1"
              memory: 500Mi
            limits:
              cpu: "2"
              memory: 1Gi
          ports:
            - containerPort: 27017
              name: mongo
          volumeMounts:
            - name: data
              mountPath: /data/db
            - name: config
              mountPath: /etc/mongod/
              readOnly: true
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: mongo-pvc
        - name: config
          configMap:
            name: mongo

创建root用户:

use admin

db.createUser({user:"root", pwd:"password", roles:[{role:"root", db:"admin"}]})

补充一张角色图:

Leave a Comment

Back to Top