k8s 搭建mongodb
at 2年前 ca MongoDB pv 888 by touch
1.共享盘创建
mkdir -p /data/mongodb/pv cat /etc/exports
#/etc/exports 内容如下 /data/mongodb/pv *(rw,sync,no_root_squash) /data/mysql/pv *(rw,sync,no_root_squash) /data/redis/pv *(rw,sync,no_root_squash)
#重启服务 systemctl restart rpcbind systemctl restart nfs
2.yaml文件
apiVersion: v1 kind: PersistentVolume metadata: name: mongodb-pv namespace: default spec: capacity: storage: 1Gi accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Retain storageClassName: nfs-mongodb nfs: path: /data/mongodb/pv server: 1.1.1.1 --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: mongodb-pvc namespace: default spec: accessModes: - ReadWriteMany resources: requests: storage: 1Gi storageClassName: nfs-mongodb --- apiVersion: v1 kind: Service metadata: name: mongodb-svc namespace: default spec: type: NodePort ports: - name: mongo port: 27017 targetPort: 27017 nodePort: 27017 protocol: TCP selector: app: mongodb --- apiVersion: apps/v1 kind: Deployment metadata: name: mongo-deploy namespace: default spec: replicas: 1 selector: matchLabels: app: mongodb template: metadata: labels: app: mongodb spec: containers: - name: mongodb image: 1.1.1.1:5000/mongo:5.0.9 imagePullPolicy: IfNotPresent env: - name: MONGO_INITDB_ROOT_USERNAME #指定用户名 value: rwuser - name: MONGO_INITDB_ROOT_PASSWORD #指定密码 value: 'L^JtMzIKD!KUcX8Z' ports: - containerPort: 27017 volumeMounts: - name: mongo-pvc mountPath: /data/db volumes: - name: mongo-pvc persistentVolumeClaim: claimName: mongodb-pvc
3.创建
kubectl apply -f mongodb.yaml
4.mongo初始化
#登录 pod #登录mongo #禁止免认证登录 db.createUser( { user: "root", pwd: "xxxxxxx", roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ] } ) #创建库 用户 use devops db.createUser( { user: "zhangsan", pwd: "yyyyyyy", roles: ["readWrite","dbAdmin"] } )
版权声明
本文仅代表作者观点,不代表码农殇立场。
本文系作者授权码农殇发表,未经许可,不得转载。
已有0条评论