| == Camel Cassandraql route on Kubernetes cluster |
| |
| This quickstart run in a Java standalone container, using Spring with |
| Apache Camel (Cassandraql component). |
| |
| This example is based on: |
| |
| * Minikube 1.11.0 (Kubernetes version >= 1.17) |
| * https://www.eclipse.org/jkube[Eclipse JKube] |
| |
| First thing you'll need to do is to prepare the environment. |
| |
| Don't forget to use a bit more memory for your Minikube setup to run this |
| example smoothly: |
| |
| [source,sh] |
| ---- |
| $ minikube start --memory 5120 --cpus=4 |
| ---- |
| |
| Once your Minikube node is up and running you'll need to run the |
| following command. In your `src/main/resource/jkube/` folder you'll find |
| two yaml files. Run the following commands using them to prepare the Cassandra cluster: |
| |
| [source,sh] |
| ---- |
| $ kubectl create -f src/main/resources/jkube/cassandra-service.yaml |
| $ kubectl create -f src/main/resources/jkube/cassandra-statefulset.yaml |
| ---- |
| |
| To check the correct startup of the cluster run the following command: |
| |
| [source,sh] |
| ---- |
| $ kubectl get statefulsets.apps |
| NAME READY AGE |
| cassandra 2/2 3h44m |
| ---- |
| |
| and check the status of the pods |
| |
| [source,sh] |
| ---- |
| $ kubectl get pods |
| NAME READY STATUS RESTARTS AGE |
| cassandra-0 1/1 Running 0 2h |
| cassandra-1 1/1 Running 0 2h |
| ---- |
| |
| You can also verify the health of your cluster by running |
| |
| [source,sh] |
| ---- |
| $ kubectl exec <pod_name> -it nodetool status |
| Datacenter: DC1-K8Demo |
| ====================== |
| Status=Up/Down |
| |/ State=Normal/Leaving/Joining/Moving |
| -- Address Load Tokens Owns (effective) Host ID Rack |
| UN 172.17.0.4 212.14 KiB 32 53.1% 9bf81ccd-4aa1-451b-b56e-c16c5ee04836 Rack1-K8Demo |
| UN 172.17.0.6 170.08 KiB 32 46.9% 69cc6f60-9ccf-439d-a298-b79b643c1586 Rack1-K8Demo |
| ---- |
| |
| === Building and running |
| |
| Navigate to the project folder where the example can be built with |
| |
| [source,sh] |
| ---- |
| $ mvn clean -Pkubernetes-install k8s:deploy |
| ---- |
| |
| When the example runs in Kubernetes, you can use the Kubectl command tool |
| to inspect the status |
| |
| To list all the running pods: |
| |
| [source,sh] |
| ---- |
| $ kubectl get pods |
| ---- |
| |
| You can follow the log for the created Pod by running: |
| |
| [source,sh] |
| ---- |
| $ mvn -Pkubernetes-install k8s:log |
| ---- |
| |
| You should then see an output similar to this: |
| |
| [source,sh] |
| ---- |
| [INFO] k8s: 2020-08-07 12:34:32,569 [main ] INFO GuavaCompatibility - Detected Guava >= 19 in the classpath, using modern compatibility layer |
| [INFO] k8s: 2020-08-07 12:34:32,834 [main ] INFO ClockFactory - Using native clock to generate timestamps. |
| [INFO] k8s: 2020-08-07 12:34:33,005 [main ] INFO NettyUtil - Did not find Netty's native epoll transport in the classpath, defaulting to NIO. |
| [INFO] k8s: 2020-08-07 12:34:34,122 [main ] INFO DCAwareRoundRobinPolicy - Using data-center name 'DC1-K8Demo' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor) |
| [INFO] k8s: 2020-08-07 12:34:34,124 [main ] INFO Cluster - New Cassandra host cassandra/172.17.0.7:9042 added |
| [INFO] k8s: 2020-08-07 12:34:34,150 [main ] INFO Cluster - New Cassandra host cassandra/172.17.0.6:9042 added |
| [INFO] k8s: 2020-08-07 12:34:36,780 [main ] INFO CqlPopulateBean - Cassandra was populated with sample values for test.users table |
| [INFO] k8s: 2020-08-07 12:34:37,372 [main ] INFO LRUCacheFactory - Detected and using LRUCacheFactory: camel-caffeine-lrucache |
| [INFO] k8s: 2020-08-07 12:34:38,012 [main ] INFO AbstractCamelContext - Apache Camel 3.7.0-SNAPSHOT (camel-1) is starting |
| [INFO] k8s: 2020-08-07 12:34:38,019 [main ] INFO AbstractCamelContext - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html |
| [INFO] k8s: 2020-08-07 12:34:38,019 [main ] INFO AbstractCamelContext - Using HealthCheck: camel-health |
| [INFO] k8s: 2020-08-07 12:34:38,664 [main ] INFO DefaultMavenCoordinates - DataStax Java driver for Apache Cassandra(R) (com.datastax.oss:java-driver-core) version 4.8.0 |
| [INFO] k8s: 2020-08-07 12:34:39,554 [s0-admin-0 ] INFO Clock - Using native clock for microsecond precision |
| [INFO] k8s: 2020-08-07 12:34:41,453 [main ] INFO InternalRouteStartupManager - Route: cassandra-route started and consuming from: timer://foo |
| [INFO] k8s: 2020-08-07 12:34:41,454 [main ] INFO AbstractCamelContext - Total 1 routes, of which 1 are started |
| [INFO] k8s: 2020-08-07 12:34:41,455 [main ] INFO AbstractCamelContext - Apache Camel 3.7.0-SNAPSHOT (camel-1) started in 3.441 seconds |
| [INFO] k8s: 2020-08-07 12:34:41,469 [main ] INFO BaseMainSupport - Using properties from: classpath:application.properties;optional=true |
| [INFO] k8s: 2020-08-07 12:34:41,557 [main ] INFO DefaultRoutesCollector - No additional Camel XML routes discovered from: classpath:camel/*.xml |
| [INFO] k8s: 2020-08-07 12:34:41,557 [main ] INFO DefaultRoutesCollector - No additional Camel XML route templates discovered from: classpath:camel-template/*.xml |
| [INFO] k8s: 2020-08-07 12:34:41,559 [main ] INFO DefaultRoutesCollector - No additional Camel XML rests discovered from: classpath:camel-rest/*.xml |
| [INFO] k8s: 2020-08-07 12:34:42,557 [1 - timer://foo] INFO cassandra-route - Query result set [1-oscerd,2-not-a-bot] |
| [INFO] k8s: 2020-08-07 12:34:47,548 [1 - timer://foo] INFO cassandra-route - Query result set [1-oscerd,2-not-a-bot] |
| [INFO] k8s: 2020-08-07 12:34:52,661 [1 - timer://foo] INFO cassandra-route - Query result set [1-oscerd,2-not-a-bot] |
| ---- |
| |
| === Cleanup |
| |
| Run following to undeploy the application and cassandra nodes |
| |
| [source,sh] |
| ---- |
| $ mvn -Pkubernetes-install k8s:undeploy |
| $ kubectl delete -f src/main/resources/jkube/cassandra-service.yaml |
| $ kubectl delete -f src/main/resources/jkube/cassandra-statefulset.yaml |
| ---- |
| |
| Make sure no pod is running |
| |
| [source,sh] |
| ---- |
| $ kubectl get pods |
| No resources found. |
| ---- |
| |
| === Help and contributions |
| |
| If you hit any problem using Camel or have some feedback, then please |
| https://camel.apache.org/support.html[let us know]. |
| |
| We also love contributors, so |
| https://camel.apache.org/contributing.html[get involved] :-) |
| |
| The Camel riders! |