Deploying Apache Camel applications built with Spring Boot on Kubernetes

Ajanthan Eliyathamby 🇱🇰
5 min readJan 25, 2024

--

In this article, I’m going to explain about how we can deploy a Apache Camel Application built on top of Spring Boot to the Kubernetes Platform. Here we will be using Minikube, a single node kubernetes cluster, helps us to deploy and test our applications on kubernetes setup in local environment.

The use case I’m taking up here is a Csv File reading from the FTP location and posting an aggregated message to a topic in ActiveMQ. As the file reading process need to avoid the duplicate reading, will be using one of the Apache Camels feature “Idempotent Consumer: FileIdempotentRepository”. Which actually need a File Share and using the NFS for it. To get more on this pattern refer the official document here.

Below diagram depicts what I’m planning to set up in my local environment.

Local Setup Diagram

1. Setting up Apache ActiveMQ and Nexus

For the above you can follow the steps provided in [1] and [2].

Once the Nexus is done, we can create docker repository using the create repository.

Also make sure to add the /etc/hosts with the docker host

here it will be: 192.168.133.135 docker-local-registry, this will help later to tag the images and push to the docker registry later on this article.

2. Setup FTP

Here, provide a FTP HOME directory. In my case it is /home/vagrant/ftp and also to keep my data files for processing, have another folder called: data-files.

So my listening location will be /home/vagrant/ftp/data-files

Then make sure the FTP is Write Enabled and also update the pam service to the below as well.

  • pam_service_name = ftp in /etc/vsftpd.conf
  • Uncomment the write_enable=YES in /etc/vsftpd.conf

Then do a restart to the FTP service

  • sudo service vsftpd status
  • sudo service vsftpd stop
  • sudo service vsftpd start

3. Setup Minikube

For various type of platform installations available and can be found here. As mentioned in the initial diagram i have been setting up in ARM64 Ubuntu, so follow the below steps to achieve the installation.

Once installed we can start the minikube, as we have setup a non-secure docker registry, we can pass that as an argument. Use the below command to start the minikube in local.

Useful commands on minikube

  • minikube status: Check the status
  • minikube addons list: Check the List of addons, useful to make sure, what are features enabled in the minikube that is running locally
  • minikube ssh: SSH into the minikube node
  • minikube ip: Get the IP address, useful for API calls as well as to find the originating IP in the case like NFS.

3. Setup NFS

After installation go to sudo vi /etc/exports and add the below content.

here, the folder will be given access from 192.168.0.0/16 all the addresses, why i gave this is my minikube ip is 192.168.49.2, so the initiating calls from this ip needs to be permitted to do operations in the NFS Server.

then,

  • sudo service nfs-kernel-server stop
  • sudo service nfs-kernel-server start
  • sudo service nfs-kernel-server status

5. Setup kubectl for Minikube Cluster Management

Follow this to setup the kubectl to manage the minikube cluster.

using the below commands we can make sure that the communication between kubectl and the minikube cluster working properly.

6. Preparing the Apache Camel Project

Refer my previous articles on [1] and [2] to get the clear picture on the camel project creation.

[1] https://medium.com/@ajanthan-eliyathamby/efficient-large-file-processing-with-apache-camel-part-1-13702a3d4b7c

Once the project logic is implemented, then we need to build it.

mvn clean package

then we need to prepare a Dockerfile to build the image, tag it and push it to the docker registry we set up using the Nexus.

Dockerfile

Execute the below command to build, tag and push the docker image.

Now the Image will be available in the Nexus Docker Registry.

deployment.yml

Here, imagePullSecrets: — name: base-credential, we need to create a secret for kubernetes to pull the docker image from the nexus docker registry.

The quickest way to create this is, first execute the login command

Here, the config json will be stored in /home/vagrant/.docker/config.json. copy the content and create a file in the server where you are executing the kubectl commands,

here, dockerconfig.json is the file which contains the content copied earlier.

Now we have created the Secrets, can execute the deployment.yml

kubectl apply -f deployment.yml

7. Testing

After executing use below commands to verify the pod status.

Place a file in the FTP directory and check the ActiveMQ whether the message count Enqueued and Dequeued properly.

References

[1] https://minikube.sigs.k8s.io/docs/start/

[2] https://www.vultr.com/docs/install-apache-activemq-on-ubuntu-20-04/

[3] https://www.fosstechnix.com/how-to-install-nexus-repository-on-ubuntu/

[4] https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/

--

--

Ajanthan Eliyathamby 🇱🇰
Ajanthan Eliyathamby 🇱🇰

Written by Ajanthan Eliyathamby 🇱🇰

Associate Architect — Enterprise Integration | 14x WSO2 | 1x HashiCorp | 1× Azure | Runner-Up WCPY 2020 | https://ajanthane.blogspot.com

No responses yet