Kubernetes Installing the MongoDB-3.6.5 cluster replica set mode

Source: Internet
Author: User
Tags auth

First, install the deployment:

The small partner who wants to create the cluster directly, follow the steps below to install it (and then record your own mistakes):

1. Create a Docker Image:

Docker build-t 144.202.127.156/library/mongodb:3.4.10.

Docker Push 144.202.127.156/library/mongodb:3.4.10 Note: Remember to replace the address with your own mirrored warehouse

from   &&    echo http://dl-4.alpinelinux.org/alpine/edge/testing >>/etc/apk/repositories & &    --no-cache mongodb numactl numactl-tools
Dockerfile2. Create on Kubernete:

Kubectl create-f mongodb.yml

Here are a few points to note:

1), the secret and Storageclass for external storage will be replaced by their own. Note: I'm using Ceph, and the rest can be used for testing, depending on my own changes or without persistent storage.

2), Mirror to your own mirror address.

3), start parameters --replset for their own, do not change can also.

ApiVersion:v1kind:Namespacemetadata:name:basic-app---ApiVersion:v1kind:Secretmetadata:namespace:basic-app Name:ceph-Secrettype:"KUBERNETES.IO/RBD"Data:key:QVFEYmVRTmJZQ1B4TFJBQUg0QS9Tb01NZjF6NHB3L0p1Y3ZUQnc9PQ==---ApiVersion:v1kind:Secretmetadata:namespace:basic-app Name:mongo-keytype:Opaquedata:key:UERVU0hWVU9KT1ZQVUVYT0JXWU8=---ApiVersion:v1kind:ConfigMapmetadata:name:mongodb-config Namespace:basic-Appdata:mongodb:|systemLog:destination:file Path:"/var/log/mongodb/mongodb.log"logappend:true processManagement:fork:false net:port:27017Bindip:0.0.0.0Security:keyfile:"/etc/conf.d/secret-key/key"authorization:enabled Storage:dbpath:/var/lib/MongoDB setParameter:enableLocalhostAuthBypass:true Authenticationmechanisms:scram-sha-1MONGOs:|mongos_exec="/usr/bin/mongos"Mongos_run="/var/run/mongodb"Mongos_user="MongoDB"mongos_ip="127.0.0.1"Mongos_port="27018"Mongos_configdb=""mongos_options=""---ApiVersion:v1kind:Servicemetadata:name:mongodb Namespace:basic-app Labels:name:mongospec:clusterIP:None ports:-port:27017Targetport:27017Selector:app:mongo-Cluster---Apiversion:apps/V1beta1kind:StatefulSetmetadata:name:mongodb Namespace:basic-Appspec:serviceName:mongodb Replicas:3Template:metadata:labels:app:mongo-cluster Spec:terminationgraceperiodseconds:10Containers:-Name:mongod Image:144.202.127.156/library/mongodb:3.6.5command: ["SH","- C","chmod 600-r/etc/conf.d/secret-key;numactl--interleave=all mongod-f/etc/conf.d/mongodb--auth--replSet ICSOC "] Resources:limits:cpu:2memory:2g requests:cpu:1memory:1g volumemounts:-name:mongodb-Data mountpath:/var/lib/MongoDB-name:mongo-config Mountpath:/etc/CONF.D-name:timezone-config Mountpath:/etc/localtime-name:secret-Key Mountpath:/etc/conf.d/Ports:-containerport:27017LivenessProbe:tcpSocket:port:27017Initialdelayseconds:15Periodseconds:20volumes:-name:mongo-config ConfigMap:name:mongodb-Config-name:timezone-config Hostpath:path:/usr/share/zoneinfo/asia/Shanghai-name:secret-Key Secret:secretName:mongo-Key volumeclaimtemplates:-Metadata:name:mongodb-Data Annotations:volume.beta.kubernetes.io/storage-class:"ceph-db"spec:accessmodes: ["readwriteonce"] Resources:requests:storage:50gi
mongodb.yml3. Initialize the cluster:
1 , connected into the container:kubectlexec-it mongodb-0/bin/SH2 , execute initialize replica set:mongors.initiate ({_id:"Icsoc", Version:1, Members: [{_id:0, Host:"mongodb-0.mongodb.basic-app.svc.cluster.local:27017"}, {_id:1, Host:"mongodb-1.mongodb.basic-app.svc.cluster.local:27017"}, {_id:2, Host:"mongodb-2.mongodb.basic-app.svc.cluster.local:27017" } ]});2. Create an administrative user:   For specific reference: https://docs.mongodb.com/manual/tutorial/enable-authentication/Use admindb.createuser ({User:"Myuseradmin", pwd:"[email protected]", roles: [{role:"Useradminanydatabase"Db:"Admin"}]}) Db.auth ("Myuseradmin","[email protected]")

3, after you can connect to create users, give role permissions to use.
Second, the following records are created detailed steps: 1, in the Kubenetes installation MongoDB cluster general idea is:

1), first in a basic image of the installation of MongoDB, starting normal without error.

2), and then clarify how the Mogodb replica set cluster is started.

3), then write the file to create the resource in Kubernetes.

4), first create a look at that do not go down, and then solve one by one.

2. Write dockerfile on the basis of Alpine:edge:

The written dockerfile are as follows:

from   &&    echo http://dl-4.alpinelinux.org/alpine/edge/testing >>/etc/apk/repositories & &    --no-cache MongoDB numactlcopy run.sh  /root/+x/root//root/ run.sh
Dockerfile

Start on Docker first, MONGO the error after connecting in:

Server has startup warnings:2018-07-15t12:25:52.064+0800 W CONTROL [main]--diaglog isDeprecated andwould be removedincha future release2018-07-15t12:25:52.183+0800I STORAGE [Initandlisten]2018-07-15t12:25:52.183+0800 I STORAGE [initandlisten] * * warning:using the XFS filesystem isstrongly recommended with the Wiredtiger storage engine2018-07-15t12:25:52.183+0800 I STORAGE [Initandlisten] * * See http://dochub.mongodb.org/core/prodnotes-filesystem First error 2018-07-15t12:26:02.364+0800 I CONTROL [initandlisten] * * Warning:you is running this process as the root user, which is  notrecommended. a second 2018-07-15t12:26:02.364+0800I CONTROL [Initandlisten]2018-07-15t12:26:02.364+0800I CONTROL [Initandlisten]2018-07-15t12:26:02.364+0800 I CONTROL [Initandlisten] * *Warning:you is running on a NUMA machine.2018-07-15t12:26:02.364+0800 I CONTROL [Initandlisten] * *We suggest launching mongod like this to avoid performance problems:2018-07-15t12:26:02.364+0800 I CONTROL [initandlisten] * * Numactl--interleave=All Mongod [other options] third 2018-07-15t12:26:02.365+0800I CONTROL [Initandlisten]2018-07-15t12:26:02.365+0800 I CONTROL [initandlisten] * * WARNING:/sys/kernel/mm/transparent_hugepage/enabled is ' always'.2018-07-15t12:26:02.365+0800 I CONTROL [initandlisten] * * We suggest setting it to'never' fourth one 2018-07-15t12:26:02.365+0800I CONTROL [Initandlisten]2018-07-15t12:26:02.365+0800 I CONTROL [initandlisten] * * WARNING:/sys/kernel/mm/transparent_hugepage/defrag is ' always'.2018-07-15t12:26:02.365+0800 I CONTROL [initandlisten] * * We suggest setting it to'never' fifth one 

1), the first error is the file system problem, has not been resolved.

2), the second error is to open the certification, in the boot parameters to add--auth on it.

3), the third error needs to precede the Mongod command with Numactl--interleave= all, execute numactl--interleave=all mongod-f/etc/in the Docker container Conf.d/mongodb in containers directly from Docker will error:

 not permitted

But in Statefulset's yml file, add command: ["sh", "-C", "Numactl--interleave=all mongod-f/etc/conf.d/mongodb--bind_ip 0.0.0.0"], Kubectl create-f mongodb.yml will not be error after creation.

  4), fourth and fifth errors need to be performed:echo never >/sys/kernel/mm/transparent_hugepage/enabled,echo never >/sys/kernel/mm /transparent_hugepage/defrag,

However, execution in the container will error, even if used initContainers to create a running environment for the MongoDB container, but also reported:

/bin/sh:can '  T create/sys/kernel/mm/transparent_hugepage/enabled:read-only file system
/bin/sh:can ' t create/sys/kernel/mm/transparent_hugepage/defrag:read-only file system

There are two ways to resolve this:

1, in all node nodes to execute the above two commands, so that after the creation of the execution has no error.

2, create demonset (temporarily still not understand), concrete can refer to :http://pauldone.blogspot.com/2017/06/mongodb-kubernetes-production-settings.html

Official Document: https://docs.mongodb.com/manual/replication/

Specifically installed on the k8s mongodb:http://k8smongodb.net/

Kubernetes Installing the MongoDB-3.6.5 cluster replica set mode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.