簡體   English   中英

公開具有訪問控制權的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

但是,當我跳到吊艙中時。 它不需要我進行任何身份驗證。 我可以執行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>

我見過這里這里 我有3個IP地址。 我應該使用哪一個?

我認為LoadBalancer可能不適合我的需求,因為它通常與backend服務一起使用以平衡節點之間的負載。 就我而言。 做寫作和replica做閱讀是master

$ 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

題:

  1. 為什么我的username:password在進行身份驗證時不被考慮?

  2. 我如何暴露我的mongo shell並讓來自Internet的客戶端通過使用我的數據庫服務器

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文件中,當應將其稱為persistentVolume時,有一個名為persistence的部分。

我建議您的values.yaml僅包含要更改的值, values.yaml包含所有內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM