11---
22title : " CNPG Recipe 12 - Exposing Postgres outside Kubernetes with Service Templates"
33date : 2024-08-26T09:38:30+02:00
4- description : " How to use CloudNativePG 1.24 's service templates to create `LoadBalancer` services for exposing PostgreSQL outside Kubernetes clusters."
4+ description : " How to use CloudNativePG's service templates to create `LoadBalancer` services for exposing PostgreSQL outside Kubernetes clusters."
55tags : ["postgresql", "postgres", "kubernetes", "k8s", "cloudnativepg", "cnpg", "postgresql", "postgres", "dok", "data on kubernetes", "load balancer", "exposing", "cloud-provider-kind" , "Service templates" , "LoadBalancer services" , "DBaaS deployment" , "Kubernetes database" , "Managed services" , "External database access" , "Custom services Kubernetes" ]
66cover : cover.jpg
77thumb : thumb.jpg
88draft : false
99---
1010
11- _ In this article, I'll introduce you to the new service template feature in
12- CloudNativePG 1.24 , which greatly simplifies the creation of services such as
11+ _ In this article, I'll introduce you to the service template feature in
12+ CloudNativePG, which greatly simplifies the creation of services such as
1313` LoadBalancer ` to expose PostgreSQL outside of your Kubernetes cluster -
1414particularly useful for streamlining Database-as-a-Service (DBaaS) deployments.
1515 I’ll walk you through setting up this feature on your laptop using ` kind ` and
@@ -18,16 +18,18 @@ capabilities in your own environment._
1818
1919<!-- more-->
2020
21- _ NOTE: this article has been updated on October 17th, 2024 with the most recent
22- version of ` cloudnative-pg ` ._
21+ _ NOTE: this article was updated on June 1st, 2026 to reflect the now mature
22+ ` LoadBalancer ` support in ` kind ` , the availability of ` cloud-provider-kind `
23+ via Homebrew and the latest available version of CloudNativePG at this time
24+ (1.29.1)._
2325
2426---
2527
26- [ CloudNativePG 1.24 ] ( https://cloudnative-pg.io/releases/cloudnative-pg-1-24.0-released/ )
27- introduces managed services and service templates, making it easier than ever
28- to create additional services—like ` LoadBalancer ` —to expose PostgreSQL outside
29- your Kubernetes cluster. This new feature is a game-changer for simplifying
30- DBaaS deployments .
28+ CloudNativePG provides managed services and service templates, making it easier
29+ than ever to create additional services (like ` LoadBalancer ` ) to expose
30+ PostgreSQL outside your Kubernetes cluster. This feature is a game-changer for
31+ simplifying DBaaS deployments, and it is now available across all supported
32+ versions of the operator .
3133
3234To help you get started, I'll show you how to test this feature on your laptop
3335using ` kind ` and ` cloud-provider-kind ` . Let’s dive in!
@@ -49,8 +51,8 @@ environment required manually creating a `LoadBalancer` service or configuring
4951an Ingress. While effective, this process added complexity and overhead to
5052DBaaS deployments.
5153
52- With the release of CloudNativePG 1.24 , this task has become significantly
53- easier. You can now define custom services for any PostgreSQL ` Cluster `
54+ With CloudNativePG, this task has become significantly easier. You can now
55+ define custom services for any PostgreSQL ` Cluster `
5456resource using service templates, making it straightforward to expose your
5557databases to external clients - even for evaluation purposes.
5658
@@ -70,8 +72,20 @@ We’ll start by creating a new cluster with `kind` to evaluate the
7072[ documentation] ( https://kind.sigs.k8s.io/docs/user/loadbalancer/ ) .
7173
7274First, [ install the ` cloud-provider-kind ` executable on your system] ( https://github.com/kubernetes-sigs/cloud-provider-kind?tab=readme-ov-file#install ) .
73- The installation method depends on your operating system. On my MacBook, I
74- chose to install it using Go:
75+ The ` LoadBalancer ` support in ` kind ` has matured considerably since this article
76+ was first published, and the recommended setup is now nicely documented in the
77+ [ official ` kind ` guide] ( https://kind.sigs.k8s.io/docs/user/loadbalancer/ ) .
78+
79+ The installation method depends on your operating system. The good news for Mac
80+ users is that ` cloud-provider-kind ` is now available via Homebrew, which is by
81+ far the simplest option:
82+
83+ ``` sh
84+ brew install cloud-provider-kind
85+ ```
86+
87+ Alternatively, you can still install it with Go or download one of the
88+ [ released binaries] ( https://github.com/kubernetes-sigs/cloud-provider-kind/releases ) :
7589
7690``` sh
7791go install sigs.k8s.io/cloud-provider-kind@latest
@@ -96,7 +110,7 @@ There are multiple installation methods, but I prefer using manifests:
96110
97111``` sh
98112kubectl apply --server-side -f \
99- https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/main/releases/cnpg-1.24 .1.yaml
113+ https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/main/releases/cnpg-1.29 .1.yaml
100114```
101115
102116## Creating the PostgreSQL Cluster
@@ -160,7 +174,7 @@ Name: cluster-example-rw-lb
160174Namespace: default
161175Labels: cnpg.io/cluster=cluster-example
162176 cnpg.io/isManaged=true
163- Annotations: cnpg.io/operatorVersion: 1.24 .1
177+ Annotations: cnpg.io/operatorVersion: 1.29 .1
164178 cnpg.io/updateStrategy: patch
165179Selector: cnpg.io/cluster=cluster-example,cnpg.io/instanceRole=primary
166180Type: LoadBalancer
@@ -191,8 +205,8 @@ interface for PostgreSQL, which is available on all major platforms. On my Mac,
191205I installed it via Homebrew:
192206
193207``` sh
194- brew install postgresql@16
195- brew link postgresql@16
208+ brew install postgresql@18
209+ brew link postgresql@18
196210```
197211
198212Ensure the installation is successful by checking the version:
@@ -201,10 +215,10 @@ Ensure the installation is successful by checking the version:
201215psql --version
202216```
203217
204- You should see something like this (16 .4 is the latest at the time of writing):
218+ You should see something like this (18 .4 is the latest at the time of writing):
205219
206220``` console
207- psql (PostgreSQL) 16 .4 (Homebrew)
221+ psql (PostgreSQL) 18 .4 (Homebrew)
208222```
209223
210224Now, let's verify the connection to the database:
@@ -231,7 +245,7 @@ Copy the retrieved password, paste it into the `psql` prompt, and you should be
231245connected to the database, seeing output similar to this:
232246
233247``` console
234- psql (16 .4 (Homebrew))
248+ psql (18 .4 (Homebrew))
235249SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
236250Type "help" for help.
237251
@@ -265,7 +279,7 @@ or `r` for any instance.
265279
266280## Conclusions
267281
268- The introduction of service templates in CloudNativePG 1.24 marks a significant
282+ Service templates in CloudNativePG mark a significant
269283step forward in simplifying and streamlining PostgreSQL deployments in
270284Kubernetes, especially in DBaaS scenarios. By enabling the easy creation of
271285custom services, such as ` LoadBalancer ` , directly within your PostgreSQL
@@ -282,8 +296,8 @@ to adopt and experiment with CloudNativePG’s new capabilities.
282296This new functionality not only reduces the overhead associated with managing
283297external database services but also aligns with the growing need for robust,
284298scalable DBaaS solutions. As Kubernetes continues to evolve as a platform for
285- running databases, features like service templates in CloudNativePG 1.24 will
286- play a crucial role in enabling efficient, reliable, and secure database
299+ running databases, features like service templates in CloudNativePG will
300+ play a crucial role in enabling efficient, reliable and secure database
287301operations through Infrastructure as Code (IaC).
288302
289303---
0 commit comments