Q59. You have a Deployment named ‘postgres-deployment’ running a PostgreSQL database server. You need to configure the PostgreSQL server with a specific configuration file stored in a ConfigMap named postgres-config’. The configuration file includes sensitive information like the PostgreSQL superuser password. How can you securely store and mount this sensitive information without compromising security?
See the solution below with Step by Step Explanation.
Explanation:
Solution (Step by Step) :
1. Create the ConfigMap:
– Create a ConfigMap named ‘postgres-config’ containing the PostgreSQL configuration file (e.g., postgresql.conf). This file will likely contain the superuser password as a plain-text value. Create the ConfigMap using ‘kubectl create configmap’ with the ‘–from-file’ flag:
kubectl create configmap postgres-config –from-file=postgresql.conf
2. Use a Secret for Sensitive Data:
– Create a Secret named postgres-password’ to securely store the PostgreSQL superuser password. Use
‘kubectl create secret generic’ with the ‘–from-literal’ flag:
kubectl create secret generic postgres-password –from-literal=postgres-password=”your_postgres_password”
3. Modify the ConfigMap:
– Update the ‘postgres-config’ ConfigMap by replacing the plain-text password in the ‘postgresql.conf with a placeholder or environment variable reference. This prevents the password from being exposed in plain text in the ConfigMap:
kubectl patch configmap postgres-config -p ‘{“data”: {“postgresql.conf”: “password =
‘$POSTGRES PASSWORD’ “}}’
4. Configure the Deployment:
– Modify the ‘postgres-deployment’ Deployment to mount both the ‘postgres-config’ ConfigMap and ‘postgres- password’ Secret as volumes in the Pod template. Use ‘volumeMounts’ to specify the mount paths and ‘volumes’ to define the volume sources:

5. Apply the Changes: – Apply the modified Deployment YAML using ‘kubectl apply -f postgres-deployment.yamr. 6. Verify the Configuration: – Verify that the PostgreSQL container is using the secure password from the Secret by connecting to the PostgreSQL instance and attempting to authenticate. ]