We are going to Use kubernetes Secret Values in Mongo Deployment yaml file.
As you know that we didnt finish the mongo deployment yaml. Now we can able to set mongo username and password.
— So now, our mongo deployment yaml referenced to secret;
xxxxxxxxxx
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongo-deployment
labels:
app: mongodb
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
— name: mongodb
image: mongo
ports:
— containerPort: 27017
resources:
requests:
memory: “64Mi”
cpu: “250m”
limits:
memory: “128Mi”
cpu: “500m”
env:
— name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mongo-secret
key: mongo-root-username
— name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongo-secret
key: mongo-root-password