Complete the code to create a PostgreSQL cluster using the operator.
apiVersion: postgresql.k8s.enterprisedb.io/v1
kind: Cluster
metadata:
name: my-postgres
spec:
instances: [1]The instances field sets the number of PostgreSQL instances. Setting it to 1 creates a single instance cluster.
Complete the code to expose the PostgreSQL service on port 5432.
apiVersion: v1 kind: Service metadata: name: postgres-service spec: ports: - port: [1] targetPort: 5432
PostgreSQL uses port 5432 by default. The service port should match this to route traffic correctly.
Fix the error in the container spec to use the correct image for the PostgreSQL operator.
spec:
template:
spec:
containers:
- name: postgres-operator
image: [1]The official PostgreSQL operator image is hosted at k8s.gcr.io/postgres-operator:latest. Using this ensures the operator runs correctly.
Fill both blanks to define a PersistentVolumeClaim for the PostgreSQL data storage.
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: postgres-pvc spec: accessModes: - [1] resources: requests: storage: [2]
ReadWriteOnce allows the volume to be mounted as read-write by a single node, suitable for PostgreSQL. 10Gi sets the storage size to 10 gigabytes.
Fill all three blanks to create a ConfigMap with database credentials and mount it as environment variables.
apiVersion: v1 kind: ConfigMap metadata: name: [1] data: POSTGRES_USER: [2] POSTGRES_PASSWORD: [3]
The ConfigMap named db-config holds the username admin and password secret123 for the PostgreSQL database environment variables.