Skip to content

Commit

Permalink
Connecting to a DB - PART 2: Kubernetes
Browse files Browse the repository at this point in the history
  • Loading branch information
tommaso-borgato committed May 8, 2024
1 parent 7057384 commit 3c1c5ab
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ include::./_includes/_titles.adoc[]
In this guide, we will extend the example created in link:simple-microservice-part1[{simple-microservice-part1}] and add Database connectivity;

include::{includedir}/_prerequisites.adoc[]

* link:simple-microservice-part1[{simple-microservice-part1}]
* You have completed link:simple-microservice-part1[{simple-microservice-part1}]

include::_includes/_constants.adoc[]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,113 @@
= {simple-microservice-database-part2}
:summary: Java Microservice using WildFly
:includedir: ../_includes
include::{includedir}/_attributes.adoc[]
include::./_includes/_titles.adoc[]
:prerequisites-time: 10

In this guide, you will learn how-to run the Docker Image we built in link:simple-microservice-database-part1[{simple-microservice-database-part1}] on Kubernetes.

include::{includedir}/_prerequisites.adoc[]
* You have completed link:simple-microservice-database-part1[{simple-microservice-database-part1}]

include::_includes/_constants.adoc[]

== PostgreSQL

We basically will repeat everything we did in link:{simple-microservice-part2}[{simple-microservice-part2}] but, before, we will deploy PostgreSQL on Kubernetes;

=== PostgreSQL configmap

Create e fine named `postgres-configmap.yaml` with the following content:

.postgres-configmap.yaml
[source,yaml,subs="normal"]
----
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-secret
labels:
app: postgres
data:
POSTGRES_DB: {postgre-sql-database}
POSTGRES_USER: {postgre-sql-user}
POSTGRES_PASSWORD: {postgre-sql-password}
----

apply the ConfigMap configuration to the Kubernetes:

[source,bash,subs="normal"]
----
kubectl apply -f postgres-configmap.yaml
----

=== PostgreSQL deployment

Create e fine named `postgres-deployment.yaml` with the following content:

.postgres-deployment.yaml
[source,yaml,subs="normal"]
----
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: 'postgres:latest'
imagePullPolicy: IfNotPresent
ports:
- containerPort: 5432
envFrom:
- configMapRef:
name: postgres-secret
----

apply the ConfigMap configuration to the Kubernetes:

[source,bash,subs="normal"]
----
kubectl apply -f postgres-deployment.yaml
----

=== PostgreSQL service

Create e fine named `postgres-service.yaml` with the following content:

.postgres-service.yaml
[source,yaml,subs="normal"]
----
apiVersion: v1
kind: Service
metadata:
name: postgres
labels:
app: postgres
spec:
type: NodePort
ports:
- port: 5432
selector:
app: postgres
----

apply the ConfigMap configuration to the Kubernetes:

[source,bash,subs="normal"]
----
kubectl apply -f postgres-service.yaml
----

Back to Guides

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include::./_includes/_titles.adoc[]
In this guide, you will learn how-to run the Docker Image we built in link:simple-microservice-part1[{simple-microservice-part1}] on Kubernetes.

include::{includedir}/_prerequisites.adoc[]
* You have completed link:simple-microservice-part1.adoc[Create a JAX-RS application using Bootable Jar - part one: bare metal]
* You have completed link:simple-microservice-part1[{simple-microservice-part1}]

include::_includes/_constants.adoc[]

Expand Down

0 comments on commit 3c1c5ab

Please sign in to comment.