Yaml files

Mongodb_nfs /mongodb-nfs. Yaml # create PV -- apiVersion: v1 kind: PersistentVolume metadata: name: mongodb-nfs-pv namespace: default spec: capacity: storage: 1Gi accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Retain storageClassName: nfs-mongodb nfs: path: /root/data/ NFS /mongodb server: 192.168.72.100 mongodb-nfs-pvc namespace: default spec: accessModes: - ReadWriteMany resources: requests: storage: 1Gi storageClassName: nfs-mongodb --- apiVersion: v1 kind: Service metadata: name: mongodb-nfs-svc namespace: default spec: type: NodePort ports: - name: mongo port: 27017 targetPort: 27017 nodePort: 30017 protocol: TCP selector: app: mongodb --- apiVersion: apps/v1 kind: Deployment metadata: name: mongo-nfs-deploy namespace: default spec: replicas: 1 selector: matchLabels: app: mongodb template: metadata: labels: app: mongodb spec: containers: - name: Mongodb image: mongo:4.0 imagePullPolicy: IfNotPresent Ports: -containerPort: 27017 volumeMounts: - name: mongo-pvc mountPath: /data/db volumes: - name: mongo-pvc persistentVolumeClaim: claimName: mongodb-nfs-pvc EOFCopy the code

The installation

kubectl apply -f /root/k3s_yaml/mongodb_nfs/mongodb-nfs.yaml
Copy the code

View related pods

[root@cs100 k3s_yaml]# kubectl get pods -A -o wide NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES Kube-system helm-install-Traefik-Rb69p 0/1 Completed 0 7d20h 10.42.0.9k3s - Master <none> <none> READINESS GATES Kube-system helm-install-Traefik-Rb69p 0/1 Completed 0 7d20h 10.42.0.9k3s Kube-system metrics-server-86cbb8457f-nkck4 1/1 Running 7 7d20h 10.42.0.83k3s -master <none> <none> kube-system Local-path-provisioner - 5FF76FC89D-s698r 1/1 Running 10 7d20h 10.42.0.87k3s -master <none> < None > Fleet-system Fleet-agent-55bfc495bd-g7mt8 1/1 Running 7 7d19h 10.42.0.85k3s -master <none> <none> default redis-84BFC7c68c-zmqwf 1/1 Running 2 40h 10.42.0.90k3s-master <none> <none> kube-system coredns-854C77959c-mvlqz 1/1 Running 7 7d20h 10.42.0.92 K3s-master <none> <none> kube-system traefik-6f9cbd9bd4-ppCMC 1/1 Running 7 7d20h 10.42.0.86k3s-master <none> <none> Db-mysql mysql-nfs-deploy-5f4fc57696-7cjKN 1/1 Running 6 5d17h 10.42.0.91k3s -master <none> <none> default Seata-server-fb6557d89-xgz9l 1/1 Running 4 2d22h 10.42.0.89k3s -master <none> <none> kube-system svclb-traefik-8rk4w 2/2 Running 19 7d20h 10.42.0.88k3s-master <none> <none> cattle-system cattle-cluster-agent-68b9fbcc5D-ghp2x 0/1 CrashLoopBackOff 642 7d19h 10.42.0.84k3s -master <none> <none> default mongo-nfs-deploy-75447854c9-l247c 1/1 Running 0 56s 10.42.0.93 k3s-master <none> <none>Copy the code

Enter the mongo

[root@cs100 k3s_yaml]# kubectl exec -it mongo-nfs-deploy-75447854c9-l247c -- bash Root @ mongo - NFS - c9 deploy - 75447854 - l247c: / # mongo mongo shell version v4.4.4 connecting to: mongo: / / 127.0.0.1:27017 /? compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("34c2aa26-783d-4da9-8969-858bae11d186") } MongoDB server version: Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see https://docs.mongodb.com/ Questions? Try the MongoDB Developer Community Forums https://community.mongodb.com --- The server generated these startup warnings when booting: 2021-04-08T02:30:51.295+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted The 2021-04-08 T02:30:51. 295 + 00:00 to: / sys/kernel/mm/transparent_hugepage/enabled is' always'. We suggest setting it to 2021-04-08 T02: 'never' 30:51. 295 + 00:00 to:  /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never' --- --- Enable MongoDB's free cloud-based monitoring service, which will then receive and display metrics about your deployment (disk utilization, CPU, operation statistics, etc). The monitoring data will be available on a MongoDB website with a unique URL accessible to you and anyone you share the URL with. MongoDB may use this information to make product improvements and to suggest MongoDB products and deployment options to you. To enable free monitoring, run the following command: db.enableFreeMonitoring() To permanently disable this reminder, run the following command: db.disableFreeMonitoring() --- >Copy the code

Example Create the admin user

> use admin

switched to db admin


> db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'}]});


Successfully added user: {
	"user" : "admin",
	"roles" : [
		{
			"role" : "userAdminAnyDatabase",
			"db" : "admin"
		}
	]
}
> 

Copy the code

Create user mongo with read and write permissions

> db.auth('admin','123456');

1

> db.createUser({ user:'mongo',pwd:'mongo',roles:[ { role:'readWrite', db: 'charge_data'}]});


Successfully added user: {
	"user" : "mongo",
	"roles" : [
		{
			"role" : "readWrite",
			"db" : "charge_data"
		}
	]
}
> 

Copy the code