rancher helm chart 集成 mongodb


前言

项目使用rancher应用商店部署服务,用到了mongoDB,这里记录下helm chart 集成mongoDB。


一、为什么需要集成mongoDB?

mongoDB为什么需要和项目服务一起部署?其实你也是可以单独部署服务,再单独部署mongoDB。本项目集成mongoDB是为了方便实施部署方便,简化难度。

二、使用步骤

1.引入mongodb依赖

从rancher chart,引入已经集成完善的mongodb chart
参考地址 : https://github.com/rancher/charts/tree/master/charts
引入的mongodb chart 放到 charts 目录

wordpress/
  Chart.yaml          # 包含了chart信息的YAML文件
  LICENSE             # 可选: 包含chart许可证的纯文本文件
  README.md           # 可选: 可读的README文件
  values.yaml         # chart 默认的配置值
  values.schema.json  # 可选: 一个使用JSON结构的values.yaml文件
  charts/             # 包含chart依赖的其他chart ,  引入的mongodb放在此处
  crds/               # 自定义资源的定义
  templates/          # 模板目录, 当和values 结合时,可生成有效的Kubernetes manifest文件
  requirements.yaml   # 依赖chart定义
  questions.yml       

2.配置使用

requirements.yaml 代码示例:

dependencies:
  - name: mongodb
    version: 7.2.6
    condition: config.mongo.install
    repository: file://./charts/mongodb

questions.yaml 关于mongodb代码示例:
代码来源于mongodb questions.yaml,只是variable对应的值增加 mongodb(mongodb.usePassword,为什么这个前缀是mongodb,是引入chart.yaml中name定义是mongodb)

# mongodb
- variable: config.mongo.install
  default: false
  required: true
  label: "部署mongodb"
  description: "如果否,则需配置外部mongodb"
  type: boolean
  group: "mongodb设置"
# 外部mongodb配置
- variable: db.url
  default:  "mongodb://localhost:27017/shorturl"
  required: true
  show_if: "config.mongo.install=false"
  label: "设置外部mongodb"
  description: "参数格式   mongodb://name:pwd@ip:端口/数据库  ,如果无密码则是  mongodb://ip:端口/数据库"
  type: string
  group: "外部mongodb设置"
  # mongodb 部署
- variable: mongodb.usePassword
  default: true
  description: "Enable Password Authentication"
  type: boolean
  label: Enable Password Authentication
  required: true
  show_if: "config.mongo.install=true"
  show_subquestion_if: true
  group: "MongoDB Settings"
  subquestions:
  - variable: mongodb.mongodbUsername
    default: "username"
    description: "MongoDB username"
    show_if: "config.mongo.install=true"
    type: string
    label: MongoDB Username
    required: true
  - variable: mongodb.mongodbPassword
    default: "password"
    description: "MongoDB Password"
    show_if: "config.mongo.install=true"
    type: password
    label: MongoDB Password
  - variable: mongodb.mongodbDatabase
    default: "database"
    description: "MongoDB Database"
    show_if: "config.mongo.install=true"
    type: string
    label: MongoDB Database
    required: true
- variable: mongodb.replicaSet.enabled
  default: true
  description: "Switch to standalone or replicaSet mongodb instance"
  show_if: "config.mongo.install=true"
  type: boolean
  label: Enable MongoDB ReplicaSet
  required: true
  group: "ReplicaSet Configuration"
  show_subquestion_if: true
  subquestions:
  - variable: mongodb.replicaSet.name
    default: "rs0"
    description: "Name of the replica set"
    show_if: "config.mongo.install=true"
    type: string
    label: ReplicaSet Name
    required: true
  - variable: mongodb.replicaSet.key
    default: ""
    description: "Key used for replica set authentication, will be auto-generated if not set"
    show_if: "config.mongo.install=true"
    type: string
    label: ReplicaSet Auth Key
- variable: mongodb.persistence.enabled
  default: true
  description: "Enable persistent volume for MongoDB"
  show_if: "config.mongo.install=true"
  type: boolean
  required: true
  label: MongoDB Persistent Volume Enabled
  show_subquestion_if: true
  group: "Persistent Volume"
  subquestions:
  - variable: mongodb.persistence.size
    default: "8Gi"
    description: "MongoDB Persistent Volume Size"
    show_if: "config.mongo.install=true"
    type: string
    label: MongoDB Volume Size
    required: true
  - variable: mongodb.persistence.storageClass
    default: ""
    description: "If undefined or set to null, using the default storageClass. Defaults to null."
    show_if: "config.mongo.install=true"
    type: storageclass
    label: Storage Class for MongoDB
  - variable: mongodb.persistence.existingClaim
    default: ""
    description: "If not empty, uses the specified existing PVC instead of creating new one"
    type: pvc
    label: Uses Existing Persistent Volume Claim for LocalStorage
    show_if: "mongodb.persistence.enabled=true&&mongodb.replicaSet.enabled=false&&config.mongo.install=true"
- variable: mongodb.service.type
  default: "ClusterIP"
  description: "MongoDB Kubernetes Service type"
  show_if: "config.mongo.install=true"
  type: enum
  group: "Service Settings"
  options:
    - "ClusterIP"
    - "NodePort"
  required: true
  label: MongoDB Service Type
  show_subquestion_if: "NodePort"
  subquestions:
  - variable: mongodb.service.nodePort
    default: ""
    description: "NodePort port number(to set explicitly, choose port between 30000-32767)"
    show_if: "config.mongo.install=true"
    type: int
    min: 30000
    max: 32767
    label: Service NodePort number
- variable: mongodb.metrics.enabled
  default: true
  description: "Start a side-car prometheus exporter"
  show_if: "config.mongo.install=true"
  type: boolean
  required: true
  label: Enable MongoDB Metrics
  show_subquestion_if: true
  group: "Metrics Settings"
  subquestions:
  - variable: mongodb.metrics.serviceMonitor.enabled
    default: false
    description: "If the operator is installed in your cluster, set to true to create a Service Monitor Entry"
    show_if: "config.mongo.install=true"
    type: boolean
    label: Create ServiceMonitor Resource for Scraping Metrics Using PrometheusOperator
    required: true

3.获取mongodb启动的变量

代码示例:

{{- define "xxx.dbUrl" -}}
{{- if .Values.config.mongo.install -}}
{{- if .Values.mongodb.usePassword -}}
mongodb://{{- .Values.mongodb.mongodbUsername -}}:{{- .Values.mongodb.mongodbPassword -}}@short-url-mongodb-headless:27017/{{- .Values.mongodb.mongodbDatabase -}}
{{- else -}}
mongodb://short-url-mongodb-headless:27017/shorturl
{{- end -}}
{{- else -}}
{{- .Values.db.url -}}
{{- end -}}
{{- end -}}

总结

以上就是今天要讲的内容,本文仅仅简单介绍了mongodb 集成的使用,有问题可以在下方评论中提出。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
回答: 如果你在卸载Rancher Helm时遇到问题,可能是由于一些错误或残留文件导致的。你可以尝试以下步骤来解决这个问题。 首先,你可以尝试清理相关目录。使用以下命令删除一些目录: ``` rm -rf /etc/ceph /etc/cni /etc/kubernetes /opt/cni /opt/rke /run/secrets/kubernetes.io /run/calico /run/flannel /var/lib/calico /var/lib/etcd /var/lib/cni /var/lib/kubelet /var/lib/rancher/rke/log /var/log/containers /var/log/pods /var/run/calico ``` 如果你有手动映射的Rancher目录,请确保将其全部删除。\[2\] 接下来,你可以尝试卸载所有挂载。使用以下命令: ``` for mount in $(mount | grep tmpfs | grep '/var/lib/kubelet' | awk '{ print $3 }') /var/lib/kubelet /var/lib/rancher; do umount $mount; done ``` 这将卸载所有与Rancher相关的挂载。\[3\] 如果以上步骤仍然无法解决问题,你可以尝试重新安装Rancher Helm,然后再尝试卸载。确保按照正确的步骤进行操作,并检查是否有任何错误消息。 希望这些步骤能够帮助你成功卸载Rancher Helm。如果问题仍然存在,请提供更多详细信息,以便我们能够更好地帮助你解决问题。 #### 引用[.reference_title] - *1* [卸载rancher出现的问题](https://blog.csdn.net/weixin_45423952/article/details/125470892)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [rancher安装及卸载](https://blog.csdn.net/LXYuuuuu/article/details/110431348)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值