k8s快速创建MongoDB

1.创建MongoDB pvc文件

如果不需要持久存储可以忽略

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mongodb-data
  namespace: t1-zdbl
spec:
  storageClassName: nfs-client  #这里使用的存储类
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 30G

2.创建deployment文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: t1-zdbl-mongodb
  namespace: t1-zdbl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: t1-zdbl-mongodb
  template:
    metadata:
      labels:
        app: t1-zdbl-mongodb
    spec:
      containers:
        - name: zdbl-mongodb
          image: mongo:4.4.15
          env:
            - name: MONGO_INITDB_ROOT_USERNAME #注意我设置了用户名和密码
              value: root
            - name: MONGO_INITDB_ROOT_PASSWORD
              value: 'qiD303d1Q$8Yq^Sj'
          ports:
            - containerPort: 27017
          volumeMounts:
            - name: mongodb-data
              mountPath: /data/db
      volumes:
        - name: mongodb-data
          persistentVolumeClaim:
            claimName: mongodb-data

3.创建svc文件

apiVersion: v1
kind: Service
metadata:
  labels:
    app: t1-zdbl-mongodb
  name: t1-zdbl-mongodb
  namespace: t1-zdbl
spec:
  type: NodePort  
  ports:
    - name: mongo
      port: 27017
      protocol: TCP
      targetPort: 27017
  selector:
    app: t1-zdbl-mongodb

应用以上文件即可

 

posted @ 2024-04-17 16:18  百衲本  阅读(62)  评论(0编辑  收藏  举报
cnblogs_post_body { color: black; font: 0.875em/1.5em "微软雅黑" , "PTSans" , "Arial" ,sans-serif; font-size: 15px; } cnblogs_post_body h1 { text-align:center; background: #333366; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 23px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h2 { text-align:center; background: #006699; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 20px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } cnblogs_post_body h3 { background: #2B6695; border-radius: 6px 6px 6px 6px; box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5); color: #FFFFFF; font-family: "微软雅黑" , "宋体" , "黑体" ,Arial; font-size: 18px; font-weight: bold; height: 25px; line-height: 25px; margin: 18px 0 !important; padding: 8px 0 5px 5px; text-shadow: 2px 2px 3px #222222; } 回到顶部 博客侧边栏 回到顶部 页首代码 回到顶部 页脚代码