根据yaml文件修改 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172apiVersion: v1kind: ConfigMapmetadata: name: mongo-config namespace: publicdata: mongodb.conf: |- dbpath=/data/mongodb #logpath=/data/mongodb/mongodb.log pidfilepath=/data/mongodb/master.pid directoryperdb=true logappend=true bind_ip=0.0.0.0 port=27017---apiVersion: apps/v1kind: StatefulSetmetadata: name: mongodb namespace: publicspec: replicas: 1 serviceName: mongodb selector: matchLabels: name: mongodb template: metadata: labels: name: mongodb spec: containers: - name: mongodb image: mongo:4.2.1 command: - sh - -c - "exec mongod -f /data/mongodb/conf/mongodb.conf" imagePullPolicy: IfNotPresent ports: - containerPort: 27017 name: mongodb protocol: TCP volumeMounts: - name: mongo-config mountPath: /data/mongodb/conf/ - name: data mountPath: /data/mongodb/ volumes: - name: mongo-config configMap: name: mongo-config - name: data hostPath: path: /data/mongodb/---kind: ServiceapiVersion: v1metadata: labels: name: mongodb name: mongodb namespace: publicspec: ports: - name: mongodb port: 27017 targetPort: 27017 selector: name: mongodb 登录mongodb创建库和用户 123456789db.auth('root','1VklxvchenD1x')show dbsuse testdb.test.insert({name:"John",age:25})# 创建test用户并授权test = db.getSiblingDB('test');test.createUser({user: "test",pwd: "test123",roles: [{ role: "dbOwner", db: "test" }]});