注:

  • 官方镜像地址: https://hub.docker.com/_/mongo?tab=description

  • docker版的mongo移除了默认的/etc/mongo.conf, 修改了db数据存储路径为 /data/db.

  • 创建configmap配置,注意不能加fork=true,否则Pod会变成Completed。

  • 存储:aliyun nas

  • svc: ClusterIP ? Headless Service ?

资源清单

configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
name: mongodb-conf
namespace: zisefeizhu
data:
mongodb.conf: |
dbpath=/data/zisefeizhu/mongodb
logpath=/data/zisefeizhu/mongodb/mongodb.log
pidfilepath=/data/zisefeizhu/mongodb/master.pid
directoryperdb=true
logappend=true
bind_ip=0.0.0.0
port=27017

storageclass.yaml

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: mongodb
namespace: zisefeizhu
mountOptions:
- nolock,tcp,noresvport
- vers=3
parameters:
volumeAs: subpath
server: "7131dxxxxxxxxxxxxxxxxxxxxxxcs.com:/mongodb/"
provisioner: nasplugin.csi.alibabacloud.com
reclaimPolicy: Retain

svc.yaml

kind: Service
apiVersion: v1
metadata:
labels:
name: mongodb
name: mongodb
namespace: zisefeizhu
spec:
type: ClusterIP
ports:
- name: mongodb
port: 27017
targetPort: 27017
selector:
name: mongodb

statefulset.yaml

apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mongodb
namespace: zisefeizhu
spec:
replicas: 1
podManagementPolicy: OrderedReady #按照顺序启动或者终止Pod
serviceName: mongodb
selector:
matchLabels:
name: mongodb
template:
metadata:
labels:
name: mongodb
spec:
containers:
- name: mongodb
image: mongo:4.2.1
command:
- sh
- -c
- "exec mongod -f /data/zisefeizhu/mongodb/conf/mongodb.conf"
imagePullPolicy: IfNotPresent
ports:
- containerPort: 27017
name: mongodb
protocol: TCP
volumeMounts:
- name: mongodb-config
mountPath: /data/zisefeizhu/mongodb/conf/
- name: data
mountPath: /data/zisefeizhu/mongodb/
volumes:
- name: mongodb-config
configMap:
name: mongodb-conf
volumeClaimTemplates: #定义创建PVC使用的模板
- metadata:
name: data
annotations: #这是指定storageclass
volume.beta.kubernetes.io/storage-class: mongodb
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi

测试

# ctl get pods -n zisefeizhu | grep mongodb
mongodb-0 1/1 Running 0 25m

连接

 ctl exec -it mongodb-0 -n zisefeizhu -- mongo
MongoDB shell version v4.2.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("de51ecc8-ce78-4e4d-8107-662f3adb0e77") }
MongoDB server version: 4.2.1
Server has startup warnings:
2021-03-29T07:18:24.047+0000 I CONTROL [initandlisten]
2021-03-29T07:18:24.047+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2021-03-29T07:18:24.047+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2021-03-29T07:18:24.047+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2021-03-29T07:18:24.047+0000 I CONTROL [initandlisten]
2021-03-29T07:18:24.047+0000 I CONTROL [initandlisten]
2021-03-29T07:18:24.047+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2021-03-29T07:18:24.047+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2021-03-29T07:18:24.047+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()
---
> show databases;
admin 0.000GB
config 0.000GB
local 0.000GB

kubernetes使用statefulset部署mongoDB 单机版 自定义配置文件、密码等的更多相关文章

  1. kubernetes之StatefulSet部署zk和kafka

    前提 至少需要三个node节点,否则修改亲和性配置 如果外部访问,需要自己暴露 需要有个storageClass,这样做的原因是避免手动创建pv了 部署zk和kafka 参考: https://www ...

  2. 为首次部署MongoDB做好准备:容量计划和监控

    如果你已经完成了自己新的MongoDB应用程序的开发,并且现在正准备将它部署进产品中,那么你和你的运营团队需要讨论一些关键的问题: 最佳部署实践是什么? 为了确保应用程序满足它所必须的服务层次我们需要 ...

  3. (转)为首次部署MongoDB做好准备:容量计划和监控

    如果你已经完成了自己新的MongoDB应用程序的开发,并且现在正准备将它部署进产品中,那么你和你的运营团队需要讨论一些关键的问题: 最佳部署实践是什么? 为了确保应用程序满足它所必须的服务层次我们需要 ...

  4. docker 部署 mongodb 并且开启远程连接

    mongodb 使用 docker 部署 mongodb 拉取镜像 docker pull mongo 可以查看镜像是否下载成功 docker images | grep mongo 应该会有如下的显 ...

  5. kubernetes集群部署

    鉴于Docker如此火爆,Google推出kubernetes管理docker集群,不少人估计会进行尝试.kubernetes得到了很多大公司的支持,kubernetes集群部署工具也集成了gce,c ...

  6. Kubernetes集群部署关键知识总结

    Kubernetes集群部署需要安装的组件东西很多,过程复杂,对服务器环境要求很苛刻,最好是能连外网的环境下安装,有些组件还需要连google服务器下载,这一点一般很难满足,因此最好是能提前下载好准备 ...

  7. Spring Boot2.0自定义配置文件使用

    声明: spring boot 1.5 以后,ConfigurationProperties取消locations属性,因此采用PropertySource注解配合使用 根据Spring Boot2. ...

  8. 基于Kubernetes集群部署skyDNS服务

    目录贴:Kubernetes学习系列 在之前几篇文章的基础,(Centos7部署Kubernetes集群.基于kubernetes集群部署DashBoard.为Kubernetes集群部署本地镜像仓库 ...

  9. Kubernetes集群部署之四Master节点部署

    Kubernetes Master节点部署三个服务:kube-apiserver.kube-controller-manager.kube-scheduler和一个命令工具kubectl. Maste ...

随机推荐

  1. URLSearchParams & Location & URL params parse

    URLSearchParams & Location & URL params parse URL params parse node.js env bug node.js & ...

  2. UI & APP

    UI & APP lanhu http://help.lanhuapp.com/hc/ http://help.lanhuapp.com/hc/kb/article/1173434/ 快速使用 ...

  3. Unity安卓apk打包过程

    前言:对于Unity开发小白来说,Android打包无疑是个头痛的问题,所以我总结了 Unity安卓APK的打包过程 第一步:下载对应版本的Android Platform 第二步:安装JDK并配置J ...

  4. Gateway网关

    前提要在注册中心把网关和服务都进行注册 通俗来说,网关就是指在客户端和服务端的一面墙,这面墙有请求转发,负载均衡,权限控制,跨域,熔断降级,限流保护等功能. 客户端发送请求,请求先通过网关,网关根据特 ...

  5. 换人!golang面试官:连怎么避免内存逃逸都不知道?

    问题 怎么避免内存逃逸? 怎么答 在runtime/stubs.go:133有个函数叫noescape.noescape可以在逃逸分析中隐藏一个指针.让这个指针在逃逸分析中不会被检测为逃逸. // n ...

  6. APP跳转小程序,小程序跳转APP

    关注公共号,搜索 "APP跳转小程序,小程序跳转APP",查看原文 前置条件: 开发环境:windows 开发框架:uni-app , H5+,nativeJS,mpvue 编辑器 ...

  7. ajax请求添加自定义header参数

    beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("X-Auth0-Token", g ...

  8. 180. 连续出现的数字 + MySql + 连续出现数字 + 多表联合查询

    180. 连续出现的数字 LeetCode_MySql_180 题目描述 代码实现 # Write your MySQL query statement below select distinct t ...

  9. HDOJ-6665(离散化+DFS求连通分量)

    Calabash and Landlord HDOJ-6665 这里考察的是离散化的知识. 首先将所有的x坐标和y坐标放入两个数组中,然后对这两个数组进行排序.因为总共的坐标数就5个所以这两个数组的大 ...

  10. Nginx常见的错误配置

    Blog:博客园 个人 翻译自Common Nginx misconfigurations that leave your web server open to attack Nginx是当前主流的W ...