在kubernetes mongo express ui上设置的mongodb副本

This post is the basic guide on installing the MongoDB replica set and providing a UI access to it on a Kubernetes cluster.

这篇文章是有关安装MongoDB副本集并在Kubernetes集群上提供对它的UI访问的基本指南。

I assume that you are already familiar with Kubernetes. I will use Google Kubernetes Engine as the Kubernetes environment, but you should be able to use any other environment. Before starting, make sure you are connected to the Kubernetes cluster.

我假设您已经熟悉Kubernetes。 我将使用Google Kubernetes Engine作为Kubernetes环境,但是您应该可以使用任何其他环境。 在开始之前,请确保您已连接到Kubernetes集群。

安装MongoDB Kubernetes运算符 (Install MongoDB Kubernetes Operator)

To install MongoDB replica set we will need to install an operator first. We will use the MongoDB Community Kubernetes Operator. For the latest and full version of installation steps, visit the official repository. Short summary:

要安装MongoDB副本集,我们需要首先安装一个操作员。 我们将使用MongoDB社区Kubernetes运营商 。 有关安装步骤的最新和完整版本,请访问官方存储库 。 简短的摘要:

# Create a namespace
kubectl create
# Download and install the operator
git clone https://github.com/mongodb/mongodb-kubernetes-operator.git
cd mongodb-kubernetes-operator
kubectl create -f deploy/crds/mongodb.com_mongodb_crd.yaml
kubectl create -f deploy/ --namespace mongodb

To make sure that the operator is installed, check if all resources are in the Ready state:

要确保已安装操作员,请检查所有资源是否都处于“就绪”状态:

kubectl get all 

The output should look like this:

输出应如下所示:

Image for post

部署测试副本集 (Deploy a test replica set)

Now you have the operator installed. Let’s deploy a test replica set:

现在,您已经安装了操作员。 让我们部署一个测试副本集:

kubectl apply -f deploy/crds/mongodb.com_v1_mongodb_cr.yaml --namespace mongodb

The deployment of the replica set will take some time (up to 5 minutes). Let’s wait until its phase is ‘Running’. To check the current state, run this command:

副本集的部署将花费一些时间(最多5分钟)。 让我们等到其阶段为“正在运行”。 要检查当前状态,请运行以下命令:

kubectl get mdb 
Image for post

Now your replica set is ready to operate. You can connect to it from inside the cluster using the following connection string:

现在,您的副本集可以使用了。 您可以使用以下连接字符串从集群内部连接到它:

mongodb://example-mongodb-0.example-mongodb-svc.mongodb.svc.cluster.local:27017,example-mongodb-1.example-mongodb-svc.mongodb.svc.cluster.local:27017,example-mongodb-2.example-mongodb-svc.mongodb.svc.cluster.local:27017/?replicaSet=example-mongodb

部署mongo-express (Deploy mongo-express)

Let’s continue and deploy a mongo-express to get the UI access to the replica set:

让我们继续并部署mongo-express以获得对副本集的UI访问:

kubectl apply -f https://gist.githubusercontent.com/StMarian/6b8aa3366ee481d9c2bc79d8ddf0bacc/raw/0a949ad9cad50d3ec8b2df40283efb9633e3e1da/mongo-express.yaml 

This will apply the mongo-express deployment and expose it using a LoadBalancer.

这将应用mongo-express部署,并使用LoadBalancer公开它。

mongo-express.yaml
mongo-express.yaml

As you can see from the code above, we set up some configuration variables for the mongo-express. The most important one is the ME_CONFIG_MONGODB_SERVER — here we provide a comma-delimited list of the hostnames of the pods, where the replica set instances are located. For more details on the configuration of the mongo-express, visit the official documentation.

从上面的代码中可以看到,我们为mongo-express设置了一些配置变量。 最重要的一个是ME_CONFIG_MONGODB_SERVER-在这里,我们提供了以逗号分隔的Pod主机名列表,副本集实例位于该Pod的主机名中。 有关mongo-express的配置的更多详细信息,请访问官方文档

For any non-test projects, you should update the username and password.

对于任何非测试项目,您应该更新用户名和密码。

Note, that this will not run on clusters that do not provide LoadBalancer support (minikube, kubeadm). In order to run this deployment on such clusters, change the type of the mongo-express Service from ‘LoadBalancer’ to ‘NodePort’.

请注意,这不会在不提供LoadBalancer支持的群集(minikube,kubeadm)上运行。 为了在此类群集上运行此部署,请将mongo-express Service的类型从“ LoadBalancer”更改为“ NodePort”。

Now let’s wait until the mongo-express service receives the external IP:

现在,让我们等到mongo-express服务收到外部IP:

Image for post

Once the mongo-express service got its IP, you can go ahead and browse its 8081 port. You will see the login window where you should provide credentials from the mongo-express.yaml:

mongo-express服务获得其IP后,就可以继续浏览其8081端口。 您将看到登录窗口,您应该在其中提供mongo-express.yaml的凭据:

Image for post

After the login you’ll see the mongo-express UI:

登录后,您将看到mongo-express UI:

Image for post

翻译自: https://medium.com/swlh/mongodb-replica-set-on-kubernetes-mongo-express-ui-3ee96804252

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值