k8s部署mongodb 测试

挂载mongodb配置文件的cm 
[root@master01 kx]# cat mongodb-config.yaml apiVersion: v1 kind: ConfigMap metadata: name: mongo-config-produce namespace: chongqing labels: app: mongo-produce data: mongodb.conf: |- dbpath=/data/middleware-data/mongodb logpath=/data/middleware-data/mongodb/mongodb.log pidfilepath=/data/middleware-data/mongodb/master.pid directoryperdb=true logappend=true bind_ip=0.0.0.0 port=27017

pv pvc 卷组

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mongodb-k8s-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
  - ReadWriteMany
  storageClassName: "mongodb-k8s-pv"
  nfs:
    server: 172.22.0.11
    path: /data/mongodata
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mongodb-k8s-pvc
  namespace: chongqing
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  storageClassName: mongodb-k8s-pv
[root@master01 kx]# cat mongodb-deploy.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: db-mongo-produce
  namespace: chongqing
  labels:
    app: mongo-produce
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo-produce
  template:
    metadata:
      labels:
        app: mongo-produce
    spec:
      containers:
        - name: mongo-produce
          image: mongo:4.2.5
          command:
            - sh
            - -c
            - "exec mongod -f /etc/mongod.conf"
          ports:
            - containerPort: 27017
          resources:
            limits:
              cpu: 1000m
              memory: 512Mi
            requests:
              cpu: 1000m
              memory: 512Mi
          livenessProbe:
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 3
            tcpSocket:
              port: 27017
          readinessProbe:
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 3
            tcpSocket:
              port: 27017
          env:
            - name: MONGO_INITDB_ROOT_USERNAME
              value: root
            - name: MONGO_INITDB_ROOT_PASSWORD
              value: 'glr0713'
          volumeMounts:
            - name: data
              mountPath: /data/middleware-data/mongodb/
            - name: config
              mountPath: /etc/mongod.conf
              subPath: mongodb.conf
            - name: localtime
              readOnly: true
              mountPath: /etc/localtime
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: mongodb-k8s-pvc
        - name: config
          configMap:
            name: mongo-config-produce
        - name: localtime
          hostPath:
            type: File
            path: /etc/localtime
[root@master01 kx]# cat  mongodb-svc.yaml 
apiVersion: v1
kind: Service
metadata:
  name: db-mongo-produce
  namespace: chongqing
  labels:
    app: mongo-produce
spec:
  type: NodePort
  ports:
    - name: mongo
      port: 27017
      targetPort: 27017
      nodePort: 30017
  selector:
    app: mongo-produce

 验证:

 艹密码杂不生效呢

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值