公开具有互联网访问控制的 GKE mongo
Expose GKE mongo with access control to Internet
我现在正在尝试实施新系统。我的系统将分为 2 个集群。首先是计算工作。 CI/CD 会非常频繁地对其进行重大更改。然后防止我的后辈发生意外,也可以节省成本。因为在计算机节点上不需要像database
那样使用100GB
现在。我正在使用 helm
设置我的 mongo-replicaset
。我的配置工作正常。这是我在安装过程中的终端日志。
每个节点安装 100GB
。他们是3个节点。
$ gcloud container clusters create elmo --disk-size=100GB --enable-cloud-logging --enable-cloud-monitoring
我已经在 values.yaml
中更改了用户名和密码
mongodbUsername: myuser
mongodbPassword: mypassword
但是,当我跳入 pod 时。它不需要我做任何身份验证。我可以执行 show dbs
$ kubectl exec -it ipman-mongodb-replicaset-0 mongo
MongoDB shell version v4.0.6
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("966e85fd-8857-46ac-a2a4-a8b560e37104") }
MongoDB server version: 4.0.6
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
2019-03-20T12:15:51.266+0000 I STORAGE [main] In File::open(), ::open for '//.mongorc.js' failed with Unknown error
Server has startup warnings:
2019-03-20T11:36:03.768+0000 I STORAGE [initandlisten]
2019-03-20T11:36:03.768+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-03-20T11:36:03.768+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-03-20T11:36:05.082+0000 I CONTROL [initandlisten]
2019-03-20T11:36:05.082+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-03-20T11:36:05.082+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-03-20T11:36:05.083+0000 I CONTROL [initandlisten]
---
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
我可以看到 2 个服务 运行 mongodb-replicaset
$ kubectl describe svc ipman-mongodb-replicaset
Name: ipman-mongodb-replicaset
Namespace: default
Labels: app=mongodb-replicaset
chart=mongodb-replicaset-3.9.2
heritage=Tiller
release=ipman
Annotations: service.alpha.kubernetes.io/tolerate-unready-endpoints: true
Selector: app=mongodb-replicaset,release=ipman
Type: ClusterIP
IP: None
Port: mongodb 27017/TCP
TargetPort: 27017/TCP
Endpoints: 10.60.1.5:27017,10.60.2.7:27017,10.60.2.8:27017
Session Affinity: None
Events: <none>
$ kubectl describe svc ipman-mongodb-replicaset-client
Name: ipman-mongodb-replicaset-client
Namespace: default
Labels: app=mongodb-replicaset
chart=mongodb-replicaset-3.9.2
heritage=Tiller
release=ipman
Annotations: <none>
Selector: app=mongodb-replicaset,release=ipman
Type: ClusterIP
IP: None
Port: mongodb 27017/TCP
TargetPort: 27017/TCP
Endpoints: 10.60.1.5:27017,10.60.2.7:27017,10.60.2.8:27017
Session Affinity: None
Events: <none>
我看过here and 。我有3个IP地址。我应该使用哪一个?
我认为 LoadBalancer
可能不符合我的需要,因为它通常与 backend
服务一起使用来平衡节点之间的负载。对于我的情况。写作是master
,阅读是replica
。
$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
gke-elmo-default-pool-c5dc6e86-1j8v asia-southeast1-a n1-standard-1 10.148.0.59 35.197.148.201 RUNNING
gke-elmo-default-pool-c5dc6e86-5hs4 asia-southeast1-a n1-standard-1 10.148.0.57 35.198.217.71 RUNNING
gke-elmo-default-pool-c5dc6e86-wh0l asia-southeast1-a n1-standard-1 10.148.0.58 35.197.128.107 RUNNING
问题:
为什么我的username:password
在认证的时候没有考虑到?
如何公开我的 mongo
shell 并让来自互联网的客户端通过使用
使用我的数据库服务器
mongo -u <user> -p <pass> --host kluster.me.com --port 27017
我已经查看了 helm chart
文档。我担心我以错误的方式使用 k8s
。所以我决定在这里问一下。
我无法回答密码问题,但为您的数据库使用单独的集群可能不是最佳选择。通过创建一个单独的集群,您被迫向世界公开您的敏感数据库。这并不理想。
我建议您在现有集群上部署 mongo。这样,您只需使用服务名称作为主机名,就可以让您的计算工作负载连接到您的 mongo。
如果您的 mongo 需要更大的驱动器,只需使用永久磁盘并在使用 helm 创建 mongo 安装时指定大小。
例如:
helm install mongo-replicaset --name whatever --set persistentVolume.size=100Gi
在您的 values.yaml
文件中,您有一个名为 persistence
的部分,而它应该被称为 persistentVolume
。
我建议您 values.yaml
只包含您要更改的值,而不是所有内容。
我现在正在尝试实施新系统。我的系统将分为 2 个集群。首先是计算工作。 CI/CD 会非常频繁地对其进行重大更改。然后防止我的后辈发生意外,也可以节省成本。因为在计算机节点上不需要像database
100GB
现在。我正在使用 helm
设置我的 mongo-replicaset
。我的配置工作正常。这是我在安装过程中的终端日志。
每个节点安装 100GB
。他们是3个节点。
$ gcloud container clusters create elmo --disk-size=100GB --enable-cloud-logging --enable-cloud-monitoring
我已经在 values.yaml
mongodbUsername: myuser
mongodbPassword: mypassword
但是,当我跳入 pod 时。它不需要我做任何身份验证。我可以执行 show dbs
$ kubectl exec -it ipman-mongodb-replicaset-0 mongo
MongoDB shell version v4.0.6
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("966e85fd-8857-46ac-a2a4-a8b560e37104") }
MongoDB server version: 4.0.6
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
2019-03-20T12:15:51.266+0000 I STORAGE [main] In File::open(), ::open for '//.mongorc.js' failed with Unknown error
Server has startup warnings:
2019-03-20T11:36:03.768+0000 I STORAGE [initandlisten]
2019-03-20T11:36:03.768+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-03-20T11:36:03.768+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-03-20T11:36:05.082+0000 I CONTROL [initandlisten]
2019-03-20T11:36:05.082+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-03-20T11:36:05.082+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-03-20T11:36:05.083+0000 I CONTROL [initandlisten]
---
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
我可以看到 2 个服务 运行 mongodb-replicaset
$ kubectl describe svc ipman-mongodb-replicaset
Name: ipman-mongodb-replicaset
Namespace: default
Labels: app=mongodb-replicaset
chart=mongodb-replicaset-3.9.2
heritage=Tiller
release=ipman
Annotations: service.alpha.kubernetes.io/tolerate-unready-endpoints: true
Selector: app=mongodb-replicaset,release=ipman
Type: ClusterIP
IP: None
Port: mongodb 27017/TCP
TargetPort: 27017/TCP
Endpoints: 10.60.1.5:27017,10.60.2.7:27017,10.60.2.8:27017
Session Affinity: None
Events: <none>
$ kubectl describe svc ipman-mongodb-replicaset-client
Name: ipman-mongodb-replicaset-client
Namespace: default
Labels: app=mongodb-replicaset
chart=mongodb-replicaset-3.9.2
heritage=Tiller
release=ipman
Annotations: <none>
Selector: app=mongodb-replicaset,release=ipman
Type: ClusterIP
IP: None
Port: mongodb 27017/TCP
TargetPort: 27017/TCP
Endpoints: 10.60.1.5:27017,10.60.2.7:27017,10.60.2.8:27017
Session Affinity: None
Events: <none>
我看过here and
我认为 LoadBalancer
可能不符合我的需要,因为它通常与 backend
服务一起使用来平衡节点之间的负载。对于我的情况。写作是master
,阅读是replica
。
$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
gke-elmo-default-pool-c5dc6e86-1j8v asia-southeast1-a n1-standard-1 10.148.0.59 35.197.148.201 RUNNING
gke-elmo-default-pool-c5dc6e86-5hs4 asia-southeast1-a n1-standard-1 10.148.0.57 35.198.217.71 RUNNING
gke-elmo-default-pool-c5dc6e86-wh0l asia-southeast1-a n1-standard-1 10.148.0.58 35.197.128.107 RUNNING
问题:
为什么我的
username:password
在认证的时候没有考虑到?如何公开我的
mongo
shell 并让来自互联网的客户端通过使用 使用我的数据库服务器
mongo -u <user> -p <pass> --host kluster.me.com --port 27017
我已经查看了 helm chart
文档。我担心我以错误的方式使用 k8s
。所以我决定在这里问一下。
我无法回答密码问题,但为您的数据库使用单独的集群可能不是最佳选择。通过创建一个单独的集群,您被迫向世界公开您的敏感数据库。这并不理想。
我建议您在现有集群上部署 mongo。这样,您只需使用服务名称作为主机名,就可以让您的计算工作负载连接到您的 mongo。
如果您的 mongo 需要更大的驱动器,只需使用永久磁盘并在使用 helm 创建 mongo 安装时指定大小。
例如:
helm install mongo-replicaset --name whatever --set persistentVolume.size=100Gi
在您的 values.yaml
文件中,您有一个名为 persistence
的部分,而它应该被称为 persistentVolume
。
我建议您 values.yaml
只包含您要更改的值,而不是所有内容。