This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git

commit 477c3a61e63bdbd4d8b402004b57e076ae425dbb
Author: Andrej Vano <av...@redhat.com>
AuthorDate: Tue Oct 17 14:56:42 2023 +0200

    [Messaging] Add kubernetes deploy steps
---
 message-bridge/README.adoc                         |  42 ++++++++
 message-bridge/pom.xml                             |  38 +++++++
 .../src/main/resources/application.properties      |   4 +
 message-bridge/src/main/resources/resources.yml    | 113 +++++++++++++++++++++
 4 files changed, 197 insertions(+)

diff --git a/message-bridge/README.adoc b/message-bridge/README.adoc
index 43eeb69..6529f64 100644
--- a/message-bridge/README.adoc
+++ b/message-bridge/README.adoc
@@ -145,6 +145,48 @@ $ java -jar target/quarkus-app/quarkus-run.jar
 [io.quarkus] (main) camel-quarkus-examples-... started in 1.163s.
 ----
 
+=== Running on Kubernetes
+
+The quarkus-maven-plugin used in this example can generate the required 
resources for deploying the application on a Kubernetes cluster. The following 
steps assume you want to run the example on a minikube cluster. If you wish to 
deploy it on a different Kubernetes cluster, you can skip the minikube-specific 
commands.
+
+First, configure and start minikube, and then configure your Docker to connect 
to its Docker daemon:
+
+----
+minikube start --cpus <cpu> --memory <memory> --addons ingress
+eval $(minikube docker-env)
+----
+
+Next, deploy the message brokers and create a persistent volume claim:
+
+----
+kubectl create -f src/main/resources/resources.yml
+----
+
+After the broker pods are up and running, you can create the Docker image with 
the example and deploy it to the cluster:
+
+----
+mvn clean package -Pkubernetes -Dquarkus.kubernetes.deploy=true
+----
+
+NOTE: This works on minikube because you've previously configured your local 
Docker environment to use the Docker daemon inside minikube. However, on a 
different Kubernetes environment, you'll need to ensure that the image is 
accessible to the cluster through alternative methods.
+
+TIP: You can omit -Dquarkus.kubernetes.deploy=true to disable automatic 
deployment. Instead, you can deploy it manually using the 
target/kubernetes/kubernetes.yml file.
+
+Once the Ingress `camel-quarkus-examples-message-bridge` has been assigned an 
IP, you can start sending messages to the application:
+
+----
+curl -X POST -H "Content-Type: text/plain" http://$(oc get ingress 
camel-quarkus-examples-message-bridge -o 
jsonpath='{.status.loadBalancer.ingress[0].ip}')/message -d 'Hello'
+----
+
+==== Clean up
+
+To remove the created resources, use the following commands:
+
+----
+kubectl delete -f target/kubernetes/kubernetes.yml
+kubectl delete -f src/main/resources/resources.yml
+----
+
 === Running on OpenShift
 
 You can also deploy this example as an OpenShift pod using the capabilities of 
the quarkus-maven-plugin.
diff --git a/message-bridge/pom.xml b/message-bridge/pom.xml
index d7046ce..d4d841c 100644
--- a/message-bridge/pom.xml
+++ b/message-bridge/pom.xml
@@ -159,6 +159,44 @@
     </dependencies>
 
     <profiles>
+        <profile>
+            <id>kubernetes</id>
+            <activation>
+                <property>
+                    <name>kubernetes</name>
+                </property>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>io.quarkus</groupId>
+                    <artifactId>quarkus-kubernetes</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>io.quarkus</groupId>
+                    <artifactId>quarkus-container-image-jib</artifactId>
+                </dependency>
+            </dependencies>
+
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>${quarkus.platform.group-id}</groupId>
+                        <artifactId>quarkus-maven-plugin</artifactId>
+                        <version>${quarkus.platform.version}</version>
+                        <configuration>
+                            <systemProperties>
+                                <quarkus.profile>kubernetes</quarkus.profile>
+                                
<quarkus.container-image.build>true</quarkus.container-image.build>
+                                
<quarkus.kubernetes.ingress.expose>true</quarkus.kubernetes.ingress.expose>
+                                
<quarkus.kubernetes.pvc-volumes.storage.claim-name>message-bridge</quarkus.kubernetes.pvc-volumes.storage.claim-name>
+                                
<quarkus.kubernetes.mounts.storage.path>/storage</quarkus.kubernetes.mounts.storage.path>
+                                
<quarkus.kubernetes.image-pull-policy>IfNotPresent</quarkus.kubernetes.image-pull-policy>
+                            </systemProperties>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
         <profile>
             <id>openshift</id>
             <activation>
diff --git a/message-bridge/src/main/resources/application.properties 
b/message-bridge/src/main/resources/application.properties
index 1ae8258..a93adfa 100644
--- a/message-bridge/src/main/resources/application.properties
+++ b/message-bridge/src/main/resources/application.properties
@@ -17,6 +17,7 @@
 quarkus.log.file.enable=true
 
 ibm.mq.host=localhost
+%kubernetes.ibm.mq.host=${MQ_SERVICE_HOST}
 %openshift.ibm.mq.host=mq
 ibm.mq.port=1414
 ibm.mq.channel=DEV.APP.SVRCONN
@@ -26,6 +27,7 @@ ibm.mq.password=passw0rd
 ibm.mq.queue=DEV.QUEUE.1
 
 quarkus.artemis.amqConnectionFactory.url=tcp://localhost:61616
+%kubernetes.quarkus.artemis.amqConnectionFactory.url=tcp://${ACTIVEMQ_SERVICE_HOST}:61616
 
%openshift.quarkus.artemis.amqConnectionFactory.url=tcp://activemq-artemis-broker:61616
 quarkus.artemis.amqConnectionFactory.username=admin
 quarkus.artemis.amqConnectionFactory.password=admin
@@ -37,6 +39,8 @@ quarkus.pooled-jms.max-connections=8
 
 quarkus.transaction-manager.object-store.directory=target/narayana
 %openshift.quarkus.transaction-manager.object-store.directory=/storage/narayana
+%kubernetes.quarkus.transaction-manager.object-store.directory=/storage/narayana
 dummy.resource.directory=target/DummyXAResource
 %openshift.dummy.resource.directory=/storage/DummyXAResource
+%kubernetes.dummy.resource.directory=/storage/DummyXAResource
 quarkus.transaction-manager.enable-recovery=true
diff --git a/message-bridge/src/main/resources/resources.yml 
b/message-bridge/src/main/resources/resources.yml
new file mode 100644
index 0000000..c7037fb
--- /dev/null
+++ b/message-bridge/src/main/resources/resources.yml
@@ -0,0 +1,113 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: activemq-deployment
+  labels:
+    app.kubernetes.io/name: activemq
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app.kubernetes.io/name: activemq
+  template:
+    metadata:
+      labels:
+        app.kubernetes.io/name: activemq
+    spec:
+      containers:
+        - name: activemq
+          image: quay.io/artemiscloud/activemq-artemis-broker
+          ports:
+            - containerPort: 61616
+          env:
+            - name: AMQ_USER
+              value: admin
+            - name: AMQ_PASSWORD
+              value: admin
+---
+apiVersion: v1
+kind: Service
+metadata:
+  labels:
+    app.kubernetes.io/name: activemq
+  name: activemq
+spec:
+  ports:
+    - name: tcp
+      port: 61616
+      targetPort: 61616
+  selector:
+    app.kubernetes.io/name: activemq
+  type: ClusterIP
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: mq-deployment
+  labels:
+    app.kubernetes.io/name: ibmmq
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app.kubernetes.io/name: ibmmq
+  template:
+    metadata:
+      labels:
+        app.kubernetes.io/name: ibmmq
+    spec:
+      containers:
+        - name: mq
+          image: icr.io/ibm-messaging/mq:9.3.2.1-r1
+          ports:
+            - containerPort: 1414
+          env:
+            - name: LICENSE
+              value: accept
+            - name: MQ_QMGR_NAME
+              value: QM1
+            - name: MQ_APP_PASSWORD
+              value: passw0rd
+---
+apiVersion: v1
+kind: Service
+metadata:
+  labels:
+    app.kubernetes.io/name: ibmmq
+  name: mq
+spec:
+  ports:
+    - name: tcp
+      port: 1414
+      targetPort: 1414
+  selector:
+    app.kubernetes.io/name: ibmmq
+  type: ClusterIP
+---
+kind: PersistentVolumeClaim
+apiVersion: v1
+metadata:
+  name: message-bridge
+spec:
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 1Gi

Reply via email to