I’m testing out Postgres in my microk8s cluster with cloudnative-pq. The installation was smooth:
sudo microk8s enable community
microk8s enable cloudnative-pg
I added a database cluster with superuser postgres
like this:
apiVersion: v1
kind: Namespace
metadata:
name: postgresql
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example
namespace: postgresql
spec:
enableSuperuserAccess: true
instances: 3
storage:
size: 1Gi
In order to expose the Postgres services, some patching is required as described in the docs.
With microk8s, the following resources needs to patched:
- configmap/nginx-ingress-tcp-microk8s-conf
- daemonset/nginx-ingress-microk8s-controller
- service/loadbalancer (if e.g. metallb is enabled)
I’m using Fluxcd in my cluster, hence I’d like to do this in my Kustomization:
patches:
- patch: |-
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-ingress-tcp-microk8s-conf
namespace: ingress
data:
"5432": "postgresql/cluster-example-rw:5432"
- target:
version: v1
kind: DaemonSet
name: nginx-ingress-microk8s-controller
namespace: ingress
patch: |-
- op: add
path: /spec/template/spec/containers/0/ports/-
value:
containerPort: 5432
hostPort: 5432
name: postgres
protocol: TCP
- target:
version: v1
kind: Service
name: loadbalancer
namespace: ingress
patch: |-
- op: add
path: /spec/ports/-
value:
name: postgres
protocol: TCP
port: 5432
targetPort: 5432
The above patches won’t work without having the yaml-files for the resources to patch. So I had to find out which resources microk8s enable ingress
created in my cluster and generate yaml-files for each of them (13 resources).
E.g.
microk8s kubectl -n ingress get configmap nginx-ingress-tcp-microk8s-conf -o yaml
With my current solution, I have to maintain these yaml-files. Is there a simpler way to generate the yaml-files? I believe I’ve to do this again after chart upgrades.
I couldn’t find any microk8s command for this, but maybe there’s a generic k8s-solution for this?