挂载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
验证:
艹密码杂不生效呢