1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| $ kubectl get secret my-mongo-mongodb -o json
$ kubectl get secret my-mongo-mongodb -o yaml > secret.yaml apiVersion: v1 data: mongodb-replica-set-key: T3MzMjVIYms2Tg== mongodb-root-password: bW9uZ29wYXNz kind: Secret metadata: annotations: meta.helm.sh/release-name: my-mongo meta.helm.sh/release-namespace: default creationTimestamp: "2022-01-13T02:01:32Z" labels: app.kubernetes.io/component: mongodb app.kubernetes.io/instance: my-mongo app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: mongodb helm.sh/chart: mongodb-10.31.3 name: my-mongo-mongodb namespace: default resourceVersion: "52760" uid: d35f498f-4bb7-43cb-a1b4-fadc6446648f type: Opaque
$ kubectl run mongodb-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mongodb:4.4.10-debian-10-r20 --command -- bash If you don't see a command prompt, try pressing enter.
# 进去 mongodb 这个是主节点,可以读写 I have no name!@mongodb-client:/$ mongo --host my-mongo-mongodb-0.my-mongo-mongodb-headless.default.svc.cluster.local:27017 -u root -p mongopass MongoDB shell version v4.4.10 connecting to: mongodb://my-mongo-mongodb-0.my-mongo-mongodb-headless.default.svc.cluster.local:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("fdece2d2-01de-4b14-a326-ed7923a3d32e") } MongoDB server version: 4.4.11 --- The server generated these startup warnings when booting: 2022-01-13T02:01:42.564+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never' 2022-01-13T02:01:42.564+00:00: /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() --- rs0:PRIMARY> show dbs admin 0.000GB config 0.000GB local 0.000GB rs0:PRIMARY> exit bye
I have no name!@mongodb-client:/$ mongo --host my-mongo-mongodb-1.my-mongo-mongodb-headless.default.svc.cluster.local:27017 -u root -p mongopass MongoDB shell version v4.4.10 connecting to: mongodb://my-mongo-mongodb-1.my-mongo-mongodb-headless.default.svc.cluster.local:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("bf4c9990-abfa-47e6-88e6-b49ce70a5c04") } MongoDB server version: 4.4.11 --- The server generated these startup warnings when booting: 2022-01-13T02:02:01.245+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never' 2022-01-13T02:02:01.245+00:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never' 2022-01-13T02:02:01.370+00:00: 2022-01-13T02:02:01.370+00:00: ** WARNING: This replica set has a Primary-Secondary-Arbiter architecture, but readConcern:majority is enabled 2022-01-13T02:02:01.370+00:00: ** for this node. This is not a recommended configuration. Please see 2022-01-13T02:02:01.370+00:00: ** https://dochub.mongodb.org/core/psa-disable-rc-majority 2022-01-13T02:02:01.371+00:00: --- --- 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() --- rs0:SECONDARY> show dbs uncaught exception: Error: listDatabases failed:{ "topologyVersion" : { "processId" : ObjectId("61df8818d1bd992fb7d6ff94"), "counter" : NumberLong(3) }, "operationTime" : Timestamp(1642040662, 1), "ok" : 0, "errmsg" : "not master and slaveOk=false", "code" : 13435, "codeName" : "NotPrimaryNoSecondaryOk", "$clusterTime" : { "clusterTime" : Timestamp(1642040662, 1), "signature" : { "hash" : BinData(0,"Q9kV+ODHLfyTrw1sN4d8momJPnw="), "keyId" : NumberLong("7052505087951765510") } } } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 Mongo.prototype.getDBs/<@src/mongo/shell/mongo.js:147:19 Mongo.prototype.getDBs@src/mongo/shell/mongo.js:99:12 shellHelper.show@src/mongo/shell/utils.js:937:13 shellHelper@src/mongo/shell/utils.js:819:15 @(shellhelp2):1:1 rs0:SECONDARY> exit bye
# 也可以转发集群里的端口到宿主机访问 mongodb $ kubectl port-forward service/my-mongo-mongodb-headless 27017:27017 Forwarding from 127.0.0.1:27017 -> 27017 Forwarding from [::1]:27017 -> 2701
|