You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/modules/ROOT/pages/dev-services.adoc
+73-14Lines changed: 73 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
= Dev Services
2
2
3
-
Quarkus supports the automatic provisioning of unconfigured services in *development and test* mode.
3
+
Quarkus supports the automatic provisioning of unconfigured services in *dev and test* mode.
4
4
We refer to this capability as Dev Services. From a developer's perspective this means that if you include an extension and don't configure it then Quarkus will automatically start the relevant service (usually using https://www.testcontainers.org/[Testcontainers] behind the scenes) and wire up your application to use this service, even pre-configuring access credentials.
5
5
6
6
NOTE: Dev Services will only be enabled in dev/test mode, so it will not affect the application running in production. If you want to disable all Dev Services you can use the quarkus.devservices.enabled=false config property, or you can simply configure the service in which case it will result in the Dev Service being disabled automatically.
@@ -11,7 +11,7 @@ More on zero config setup of datasources can be found https://quarkus.io/guides/
11
11
12
12
== Replace Database Extensions
13
13
14
-
Instead of the built-in h2 database, we're now going to use an external database. Swapping out from one database provider to another is fairly trivial with Quarkus. We just remove the h2 extension and add the postgresql extension instead:
14
+
Instead of the built-in h2 database, we're now going to use an external database. Swapping out from one database provider to another is fairly trivial with Quarkus. In our case we just need to remove the h2 extension and add the postgresql extension instead:
You will now see that Quarkus has reloaded and started up a Postgresql database dev service:
61
+
Notice in the logs how Quarkus has reloaded and started up a Postgresql database dev service:
64
62
65
63
[.console-output]
66
64
[source,text]
67
65
----
68
-
69
-
--
70
-
Checking Podman Environment
71
66
2023-03-16 08:06:56,882 INFO [io.qua.dat.dep.dev.DevServicesDatasourceProcessor] (build-13) Dev Services for the default datasource (postgresql) started - container ID is c7c9a6ccf029
72
67
----
73
68
74
69
== Verify Postgresql testcontainer is running
75
70
76
-
You can now also verify/access the dev servicescontainer via Podman:
71
+
Let's verify in Docker/Podman that the dev services container is running. You should see 2 containers, one testcontainers/ryuk container which orchestrates the dev services, and another postgres container which is running the database and which is automatically wired into our Quarkus dev mode:
Let's stop dev mode for now to verify that the Postgres container also stops when we're done with dev mode by sending a `CTRL+C` in the terminal and checking again with docker ps. Notice that the postgres container has disappeared as expected.
Reminder: Once the tests have run, send `CTRL+C` since Quarkus CLI starts tests in continuous mode.
144
+
--
145
+
====
146
+
147
+
Notice in the logs that Quarkus and TestContainers work in unison to spin up the Postgres container again, run the tests, and then tear down the container again once done.
2023-07-04 17:40:04,096 INFO [org.tes.doc.DockerClientProviderStrategy] (build-23) Found Docker environment with Environment variables, system properties and defaults. Resolved dockerHost=unix:///run/user/1000/podman/podman.sock
157
+
2023-07-04 17:40:04,100 INFO [org.tes.DockerClientFactory] (build-23) Docker host IP address is localhost
158
+
2023-07-04 17:40:04,235 INFO [org.tes.DockerClientFactory] (build-23) Connected to docker:
159
+
Server Version: 4.5.1
160
+
API Version: 1.41
161
+
Operating System: fedora
162
+
Total Memory: 31787 MB
163
+
2023-07-04 17:40:04,254 INFO [org.tes.uti.ImageNameSubstitutor] (build-23) Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
164
+
2023-07-04 17:40:04,257 INFO [org.tes.DockerClientFactory] (build-23) Checking the system...
165
+
2023-07-04 17:40:04,258 INFO [org.tes.DockerClientFactory] (build-23) ✔︎ Docker server version should be at least 1.6.0
166
+
2023-07-04 17:40:05,038 INFO [tc.doc.io/postgres:14] (build-23) Creating container for image: docker.io/postgres:14
167
+
----
168
+
169
+
170
+
112
171
113
172
== [Optional] Re-deploy to Kubernetes
114
173
@@ -132,9 +191,9 @@ NOTE: We added a %prod. prefix to some of the properties. This prefix makes it
132
191
133
192
=== Create a postgresql database
134
193
135
-
There are several ways to deploy a Postgresql Database to Kubernetes. If you're using Openshift, you could create one easily through the UI (Developer Perspective > +Add > Database > PostgreSQL). Just make sure your database name, username and password match up with what you have configured in your application.properties or secrets.
194
+
There are several ways to deploy a Postgresql Database to Kubernetes. If you're using Openshift, you could create one easily through the UI (Developer Perspective > +Add > Database > PostgreSQL). Make sure your database name, username and password match up with what you have configured in your application.properties or secrets.
136
195
137
-
You can also create the following Kubernetes manifest for a simple ephemeral instance:
196
+
Alternatively you can also create the following Kubernetes manifest for a simple ephemeral instance:
Copy file name to clipboardExpand all lines: documentation/modules/ROOT/pages/kubernetes.adoc
+77-23Lines changed: 77 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,18 @@
1
1
= Deploying to Kubernetes
2
2
3
-
IMPORTANT: You will need a public container registry to store your image. If you don't have an account, we recommend you to create a free account at http://quay.io[window=_blank].
In this chapter we will push our newly built application to Kubernetes. If you don't have a Kubernetes instance at your disposal, you can create a free Openshift Sandbox instance on https://developers.redhat.com/developer-sandbox[developers.redhat.com/sandbox].
7
+
8
+
9
+
10
+
IMPORTANT: You will need a public container registry to store your image. If you don't have an account, we recommend to create a free account at http://quay.io[window=_blank].
4
11
5
12
Our examples will be using the `quay.io` container registry and the `myrepo` organization, but you should change it to match your configuration.
6
13
7
14
== Adding the Kubernetes and Jib extensions
8
15
9
-
You need a container registry that is accessible from your Kubernetes cluster to deploy the application container image in it.
10
-
11
16
In this chapter we'll be using the Quarkus Kubernetes Extension to create the Kubernetes deployment file, and the Quarkus Jib Extension to create and push the container image to your container registry without the need of a local podman/docker instance.
== Deploy your application to your Kubernetes cluster
119
129
120
-
When a Kubernetes extension is present in the classpath, a Kubernetes deployment file is scaffolded for you during the package phase.
130
+
When a Kubernetes extension is present in the classpath, Quarkus will scaffold a Kubernetes deployment file in your target folder during the package phase. We can apply it to deploy the application to our Kubernetes cluster:
131
+
132
+
NOTE: You will need the https://kubernetes.io/docs/tasks/tools/[kubectl] or oc cli tool installed locally for the apply command below. https://developers.redhat.com/blog/2021/04/21/access-your-developer-sandbox-for-red-hat-openshift-from-the-command-line#[Here are instructions] to install the oc tool and log in to your Openshift Sandbox.
121
133
134
+
[tabs]
135
+
====
136
+
kubectl::
137
+
+
138
+
--
122
139
[.console-input]
123
140
[source,bash]
124
141
----
125
142
kubectl apply -f target/kubernetes/kubernetes.yml
126
143
----
144
+
--
145
+
oc::
146
+
+
147
+
--
148
+
[.console-input]
149
+
[source,bash]
150
+
----
151
+
oc apply -f target/kubernetes/kubernetes.yml
152
+
----
153
+
--
154
+
====
127
155
128
156
[.console-output]
129
157
[source,text]
@@ -133,52 +161,63 @@ service/tutorial-app created
133
161
deployment.apps/tutorial-app created
134
162
----
135
163
136
-
You might need to wait for some seconds until your application is up and running.
164
+
[TIP]
165
+
=====
166
+
With the Quarkus CLI tool deploying is even easier. Instead of the above `kubectl apply` command, you can simply run `quarkus deploy` to deploy the application to your cluster:
167
+
[.console-input]
168
+
[source,bash,subs="+macros,+attributes"]
169
+
----
170
+
quarkus deploy
171
+
----
172
+
=====
173
+
174
+
You might need to wait a few seconds until your application is up and running. Once it is, let's get the url to test:
175
+
137
176
138
177
[tabs]
139
178
====
140
-
Minikube::
179
+
Openshift Sandbox / Kubernetes on AWS::
141
180
+
142
181
--
182
+
If using a hosted Kubernetes cluster like OpenShift (Sandbox) on AWS then use curl and the EXTERNAL-IP address with port `8080` or get it using `kubectl`:
183
+
143
184
:tmp-service-exposed: tutorial-app
144
185
145
-
[#{section-k8s}-ip-port-minikube]
186
+
[#{section-k8s}-ip-port-service]
146
187
[.console-input]
147
188
[source,bash,subs="+macros,+attributes"]
148
189
----
149
-
IP=$(minikube ip)
150
-
PORT=$(kubectl get service/{tmp-service-exposed} -o jsonpath="{.spec.ports[*].nodePort}")
190
+
IP=$(kubectl get service {tmp-service-exposed} -o jsonpath="{.status.loadBalancer.ingress[0].hostname}")
191
+
PORT=$(kubectl get service{tmp-service-exposed} -o jsonpath="{.spec.ports[0].port}")
151
192
echo $IP:$PORT
152
193
----
153
194
--
154
-
Hosted::
195
+
Minikube::
155
196
+
156
197
--
157
-
If using a hosted Kubernetes cluster like OpenShift then use curl and the EXTERNAL-IP address with port `8080` or get it using `kubectl`:
158
-
159
198
:tmp-service-exposed: tutorial-app
160
199
161
-
[#{section-k8s}-ip-port-openshift]
200
+
[#{section-k8s}-ip-port-minikube]
162
201
[.console-input]
163
202
[source,bash,subs="+macros,+attributes"]
164
203
----
165
-
IP=$(kubectl get service {tmp-service-exposed} -o jsonpath="{.status.loadBalancer.ingress[0].ip}")
166
-
PORT=$(kubectl get service{tmp-service-exposed} -o jsonpath="{.spec.ports[*].port}")
204
+
IP=$(minikube ip)
205
+
PORT=$(kubectl get service/{tmp-service-exposed} -o jsonpath="{.spec.ports[*].nodePort}")
167
206
echo $IP:$PORT
168
207
----
169
208
--
170
-
Hosted on AWS::
209
+
Hosted::
171
210
+
172
211
--
173
212
If using a hosted Kubernetes cluster like OpenShift then use curl and the EXTERNAL-IP address with port `8080` or get it using `kubectl`:
174
213
175
214
:tmp-service-exposed: tutorial-app
176
215
177
-
[#{section-k8s}-ip-port-service]
216
+
[#{section-k8s}-ip-port-openshift]
178
217
[.console-input]
179
218
[source,bash,subs="+macros,+attributes"]
180
219
----
181
-
IP=$(kubectl get service {tmp-service-exposed} -o jsonpath="{.status.loadBalancer.ingress[0].hostname}")
220
+
IP=$(kubectl get service {tmp-service-exposed} -o jsonpath="{.status.loadBalancer.ingress[0].ip}")
182
221
PORT=$(kubectl get service {tmp-service-exposed} -o jsonpath="{.spec.ports[*].port}")
183
222
echo $IP:$PORT
184
223
----
@@ -200,4 +239,19 @@ curl $IP:$PORT/hello
200
239
Hello y'all!
201
240
----
202
241
203
-
TIP: You can build, push and deploy the container image by running: `./mvnw clean package -Dquarkus.kubernetes.deploy=true`
242
+
[sidebar]
243
+
--
244
+
TIP: If you're using Openshift (Sandbox) and would like to create a url you can share to the outside world, you can create it like so:
245
+
[.console-input]
246
+
[source,bash,subs="+macros,+attributes"]
247
+
----
248
+
oc create route edge --service=tutorial-app
249
+
url=$(oc get route tutorial-app -o jsonpath='{.spec.host}')
0 commit comments