Reputation: 3
apiVersion: v1
kind: ConfigMap
metadata:
name: mongodb-config
data:
mapConfig: |
- dbName: dbName-database1
label: Database1
- dbName: dbName-database2
label: Database2
- dbName: dbName-database3
label: Database3
- dbName: dbName-database4
label: Database4
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-server
spec:
replicas: 4
selector:
matchLabels:
app: backend-server
template:
metadata:
labels:
app: backend-server
spec:
containers:
- name: backend-server
image: backend-server-image:latest
imagePullPolicy: IfNotPresent
env:
- name: DB_NAME
valueFrom:
configMapKeyRef:
name: mongodb-config
key: mapConfig
resources:
requests:
cpu: "250m"
limits:
cpu: "500m"
ports:
- containerPort: 3000
apiVersion: v1 kind: Service metadata:
name: backend-server-service spec: type: LoadBalancer selector: app: backend-server ports:
- protocol: TCP port: 3000 targetPort: 3000
I have used the configMap but I got all the values in env is there any way that I can get the dbName unique in every pod
I got all the env but like I want dbName: dbName-database1 label: Database1
In the first pod rest like same for all
Upvotes: 0
Views: 62
Reputation: 2260
Question: is there any way that I can get the dbName unique in every pod
I suggest you to create 4 different Deployment
s as the idea of Deployment
(and in the end Pod
s) is to be exactly the same, but as you want to make it different, so you should have 4 different Deployments
Other way to minimize number of duplicated code is to use helm and create chart
, because Kubernetes by default doesn't support dynamic values
Upvotes: 0