第1部分。IKS (PART 1. IKS)
MongoDB is a cross-platform document-oriented database. Classified as a NoSQL database, MongoDB eschews the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas, making the integration of data in certain types of applications easier and faster.
MongoDB是一个跨平台的面向文档的数据库。 被归类为NoSQL数据库的MongoDB避开了传统的基于表的关系数据库结构,转而使用具有动态模式的类似JSON的文档,从而使数据在某些类型的应用程序中的集成更加容易和快捷。
In IBM Cloud™ you can configure your installation from the Create tab, and then install it with a single click instead of executing the Helm installation directly. Your Helm Chart is installed by using IBM Cloud Schematics, and after the installation is complete, you can view the Chart instance, update the version, or uninstall from your Schematics workspace. Using Schematics you can enable Infrastructure as Code (IaC) by codifying your IBM Cloud resources with Terraform and use Schematics workspaces to start automating the provisioning and management of your resources. If you are installing an instance for a production configuration, review the considerations for adjusting the configuration parameters.
在IBM Cloud™中,您可以从“创建”选项卡配置安装,然后单击一次安装,而不是直接执行Helm安装。 使用IBM Cloud Schematics安装了Helm Chart,完成安装后,您可以查看Chart实例,更新版本或从Schematics工作空间中卸载。 使用Schematics,您可以通过使用Terraform编码IBM Cloud资源来启用基础结构即代码(IaC),并使用Schematics工作空间来开始自动化资源的供应和管理。 如果要为生产配置安装实例,请查看调整配置参数的注意事项。
先决条件 (Prerequisite)
- Before starting, you need to have IKS clusters on IBM cloud. 开始之前,您需要在IBM Cloud上拥有IKS集群。
If you don’t have the cluster, provisioning it first at IBM cloud portal https://cloud.ibm.com/kubernetes/overview . IKS support 2 types of infrastructure, Classic and VPC. Classic is general one but IBM Cloud Virtual Servers for VPC offer agile scalability for easy business growth, high availability for better customer satisfaction, security for your workloads and lower total cost of ownership. It provides high speed network interface and large amount of cores.
如果没有集群,请首先在IBM云门户h ttps://cloud.ibm.com/kubernetes/overview上进行配置 。 IKS支持两种类型的基础架构:经典和VPC。 Classic是通用的一种,但是用于VPC的IBM Cloud Virtual Servers提供了敏捷的可伸缩性,可以轻松实现业务增长,提供高可用性以提高客户满意度,为工作负载提供安全性并降低总体拥有成本。 它提供了高速网络接口和大量内核。
2. Create namespace for mongodb like “mongodb”, but you can use existing one.
2.为mongodb创建名称空间,例如“ mongodb”,但是您可以使用现有名称空间。
The easiest way to create namespace is using Web Terminal on cluster overview screen. The shell has authority already, you don’t need to login with user and password.
创建名称空间的最简单方法是在群集概述屏幕上使用Web终端。 该外壳已经具有权限,您无需使用用户名和密码登录。
$ kubectl get ns
NAME STATUS AGE
default Active 21h
ibm-cert-store Active 21h
ibm-observe Active 20h
ibm-operators Active 21h
ibm-system Active 21h
kube-node-lease Active 21h
kube-public Active 21h
kube-system Active 21h
$ kubectl create ns mongodb
namespace/mongodb created
3. Install “IBM Cloud Block storage plug-in” from the catalog. It support dynamic creation of PV with “ibm-block-storage-driver”.
3.从目录中安装“ IBM Cloud Block存储插件”。 它支持使用“ ibm-block-storage-driver”动态创建PV。
设置MongoDB (Provisioning MongoDB)
From the catalog of IBM cloud portal, you can see 3 kinds of MongoDB. You will work with MongoDB, which is first one.
从IBM云门户的目录中,您可以看到3种MongoDB。 您将使用MongoDB,这是第一个。
Click the tile “MongoDB” and then you go to the Helm chart configuration screen. Select the target IKS, not VMware vCenter server.
单击磁贴“ MongoDB”,然后转到Helm图表配置屏幕。 选择目标IKS,而不是VMware vCenter服务器。
And then select your cluster and namespace, which are created previously.
然后选择您之前创建的群集和名称空间。
There are several values, you need to update at “Set the deployment values” as below. It’s just example, you can change it with yours.
有几个值,您需要按如下所示在“设置部署值”处进行更新。 这只是示例,您可以根据自己的需要进行更改。
auth.username : admin
auth.password : admxx
auth.rootPassword : passxx
auth.database : sample
When all configurations are setup and then Click “Install” button at right-bottom of the screen. You can check the installation progress and logs from the “Schematics” workspace for MongoDB.
设置完所有配置后,单击屏幕右下角的“安装”按钮。 您可以从MongoDB的“示意图”工作空间中检查安装进度和日志。
如何访问MongoDB进行操作 (How to Access MongoDB for manipulating)
Option 1) Web terminal
选项1)网络终端
I explained it previously for creating namespace. When you log in to Web terminal, you have to go in to the container, MongoDB
我之前解释过创建名称空间的方法。 登录到Web终端时,您必须进入容器MongoDB
$ kubectl get pods -n mongodb
NAME READY STATUS RESTARTS AGE
mongodb4b-0bf5–4c-96c489bd9–4zt7c 1/1 Running 0 13h$ kubectl -n mongodb exec -it mongodb4b-0bf5–4c-96c489bd9–4zt7c bash
mongodb4b-0bf5–4c-96c489bd9:/$ echo "you are in container shell"
Option 2) Kubernetes portal
选项2)Kubernetes门户
Playing with MongoDB inside container
在容器内玩MongoDB
- check the parameters, which are defined when you install the MongoDB 检查安装MongoDB时定义的参数
$ env | grep MONGO
MONGODB4B_0BF5_4C_SERVICE_PORT=27017
MONGODB_DISABLE_SYSTEM_LOG=no
MONGODB_ENABLE_IPV6=no
MONGODB_PASSWORD=admin
MONGODB4B_0BF5_4C_PORT=tcp://172.21.xx:27017
MONGODB4B_0BF5_4C_PORT_27017_TCP=tcp://172.21.xx:27017
MONGODB4B_0BF5_4C_SERVICE_PORT_MONGODB=27017
MONGODB4B_0BF5_4C_PORT_27017_TCP_PROTO=tcp
MONGODB_DATABASE=sampledb
MONGODB_ROOT_PASSWORD=passxx
MONGODB_ENABLE_DIRECTORY_PER_DB=no
MONGODB_SYSTEM_LOG_VERBOSITY=0
MONGODB4B_0BF5_4C_PORT_27017_TCP_ADDR=172.21.xx
MONGODB_USERNAME=admin
MONGODB4B_0BF5_4C_PORT_27017_TCP_PORT=27017
MONGODB4B_0BF5_4C_SERVICE_HOST=172.21.xx
2. running MongoDB cli
2.运行MongoDB CLI
$ mongo admin -u root -p passxx
$ mongo sampledb -u admin -p admin
3. sample SQL command
3.示例SQL命令
> show dbs
> use admin
> show tables> db.mytable.insertOne({ item: "canvas", qty: 100, tags: ["cotton"], size: { h: 28, w: 35.5, uom: "cm" } })
> db.mytable.find()
> db.mytable.count()> use admin
> db.system.users.find({"user":"admin"})> use mytable
> db.createUser(
{user: "user02",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "admin" },
{ role: "readWrite", db: "sampledb" }
]})
第2部分。 (PART 2. OpenShift)
At IKS case, we install it from the catalog of IBM Cloud, but for OpenShift we need can use 2 options, OperatorHub and Template from OpenShift web portal. Two options support different docker images of MongoDB. In my test, I choose the Template, which is easier than OperatorHub’s. Because it requires more prerequisite.
在IKS情况下,我们从IBM Cloud的目录中进行安装,但是对于OpenShift,我们需要使用两个选项,即来自OpenShift Web门户的OperatorHub和Template。 有两个选项支持MongoDB的不同docker映像。 在测试中,我选择了Template,它比OperatorHub的模板更容易。 因为这需要更多的先决条件。
- OperatorHub OperatorHub
2. Template
2.模板
Developer Catalog at above screen capture is Template catalog support as below.
上面屏幕截图中的Developer Catalog是模板目录支持,如下所示。
There are several values, you need to update at “Set the deployment values” as below. It’s just example, you can change it with yours.
有几个值,您需要按如下所示在“设置部署值”处进行更新。 这只是示例,您可以根据自己的需要进行更改。
MongoDB connection username : admin
MongoDB connection password : admxx
MongoDB database name : sampledb
MongoDB admin password : passxx
Playing with MongoDB inside container
在容器内玩MongoDB
After install the Template, You need to check the POD and go into the terminal to manipulate MongoDB data.
安装模板后,您需要检查POD并进入终端以操作MongoDB数据。
Database operation is same with IKS case above, but different one is root user id, which is admin.
数据库操作与上述IKS情况相同,但不同的是root用户ID(即admin)。
sh-4.2$ env | grep MONGODB
MONGODB_PORT_27017_TCP=tcp://172.21.xx:27017
MONGODB_PORT=tcp://172.21.xx:27017
MONGODB_PORT_27017_TCP_PORT=27017
MONGODB_ADMIN_PASSWORD=passxx
MONGODB_SERVICE_HOST=172.21.96.83
MONGODB_DATABASE=sampledb
MONGODB_PORT_27017_TCP_PROTO=tcp
MONGODB_PASSWORD=admxx
MONGODB_VERSION=3.6
MONGODB_PORT_27017_TCP_ADDR=172.21.xx
MONGODB_SERVICE_PORT=27017
MONGODB_USER=admin
MONGODB_SERVICE_PORT_MONGO=27017sh-4.2$ mongo admin -u admin -p passxx
sh-4.2$ mongo sampledb -u admin -p admin