DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Spinnaker Meets Minikube: Part 1
  • 13-Step Guide to Performance Testing in Kubernetes
  • Fast Deployments of Microservices Using Ansible and Kubernetes
  • Redefining DevOps: The Transformative Power of Containerization

Trending

  • Docker Model Runner: Streamlining AI Deployment for Developers
  • How to Convert XLS to XLSX in Java
  • AI-Driven Test Automation Techniques for Multimodal Systems
  • Contextual AI Integration for Agile Product Teams
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Building an ActiveMQ Docker Image on Kubernetes

Building an ActiveMQ Docker Image on Kubernetes

This article will give you a primer on installing Apache ActiveMQ and building it on a Docker image to deploy to Kubernetes.

By 
Nikhil Bhide user avatar
Nikhil Bhide
·
Oct. 18, 18 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
41.1K Views

Join the DZone community and get the full member experience.

Join For Free

In our project, we require a message broker to pave a way for asynchronous communication between different microservices. So, one of the microservices required is a messaging service. In this example, we are going to use Apache ActiveMQ as a message broker.

In order to deploy messaging microservice, we must containerize ActiveMQ. It’s a very straightforward process as we are only going to set up 1 node cluster.

Technically we require taking the base image of Linux and getting and installing ActiveMQ 5.16.5. The final step is to start ActiveMQ. So, let’s get started.

  • Create a Docker file, a script file with following instructions.

FROM openjdk:8-jre-alpine
RUN wget -O activemq.tar.gz http://archive.apache.org/dist/activemq/5.15.6/apache-activemq-5.15.6-bin.tar.gz 
RUN tar -xzf activemq.tar.gz 
CMD ["apache-activemq-5.15.6/bin/activemq", "console"]


  • Navigate to the folder in which the Docker file is saved and create a Docker image by running command  docker build :

Image title

  • Check whether the image is registered in local Docker repo with Docker images.

Note that initially you will notice <none> under repository. In order to tag the image, run command docker tag <IMAGE_ID> <yourdockerhubname>/image-name.

For example: docker tag c35d0594bffc nikbhi15docker/k8s-make-my-vacation-queue .Image title


  • Run the container using Docker using command:

  •  docker run nikbhi15docker/k8s-make-my-vacation-queue 


    Image title


    • Find out IP address of our container and connect to admin console on <container_ip>:8161.Image title


    Image title

    Image title



    Image title


    Okay, so ActiveMQ started. But seriously, what the heck is happening? Let's understand!

    Those who are familiar with Docker can simply stop reading this article and go for a coffee break. Others hold on!

    The entire magic is in the Docker file – YES only 4 instructions.

    FROM openjdk:8-jre-alpine


    It implies that we want to use the base image of openJDK:8-jre-alpine. Its one of the smallest Linux Java images with Alpine. If you are observing carefully, then you will have noticed the usage of openjdk and not Oracle JDK. Yes, it’s now official that OpenJDK has better official images than Oracle JDK. Even the regular images are smaller, including the alpine alternatives.

    RUN wget -O activemq.tar.gz http://archive.apache.org/dist/activemq/5.15.6/apache-activemq-5.15.6-bin.tar.gz


    It’a no-brainer. This instruction is downloading the MQ setup artifact from thr official Apache ActiveMQ site and this command is getting executed on the top of our Linux base image. So after this, you have Linux, Java and ActiveMQ.

    I am sure by now you must have understood the gist of this article and you can definitely anticipate what is to be followed in this article. However, I will still explain the remaining steps from the perspective of completeness of this article.

    RUN tar -xzf activemq.tar.gz


     tar is Short for Tape Archive, and sometimes referred to as tarball, a file that has the TAR file extension is a file. Above command unpacks the tar.gz file.

     -xzf are nothing but different flags/arguments passed to tar  command.

     -x --extract  = extract files from an archive

     -z, --gzip = gzipped files eg. for tar.gz packages

     -f, --file ARCHIVE  = use archive file or device ARCHIVE

    CMD ["apache-activemq-5.15.6/bin/activemq", "console"]


    Here we are using default entry point which is  /bin/sh –c . The CMD specifies arguments that will be fed to the ENTRYPOINT. The format of command CMD is

     CMD ["executable","param1","param2"] 

    Therefore what we are doing is forking out a process

     /bin/sh -c command param1 param2 . This is how the ActiveMQ process gets started.

    That’s it in this article. In the next article, we will see how to use a Spring Boot JMS application to connect with this messaging service in microservices architecture using K8s.

    Just wait a moment!

    We have not yet accomplished the mission. Our mission is to run this image on K8s. Let’s cross the finish line in the last section of this article.

    In order to run this Docker image on K8S, we require the pod and service definition. Here are those definitions.

    Pod definition – Notice carefully that in this example, I am using image pushed to my Dockerhub that is nikbhi15docker/k8s-make-my-vacation-queue.

    Image title


    Service definition – Notice that we are using nodePort and thrport to be exposed is 32090 and from the container the port is 8161. NodePort exposes the service on each Node’s IP at a static port.

    Image title

    Start minikube using command  minikube start .

    Then navigate to the directory in which queue-pod and queue-service definitions are saved. Apply pod and service definitions as follows. In short, applying definition implies that you are starting a pod and a service.


    kubectl apply –f queue-pod.yaml



    kubectl queue-service.yaml


    Find the IP address of minikube cluster (minikube ip) and navigate to :32190   and you should admin console of ActiveMQ (username – admin & password – admin).

    You can refer to GitHub.

    Docker (software) Kubernetes Archive file microservice Command (computing)

    Opinions expressed by DZone contributors are their own.

    Related

    • Spinnaker Meets Minikube: Part 1
    • 13-Step Guide to Performance Testing in Kubernetes
    • Fast Deployments of Microservices Using Ansible and Kubernetes
    • Redefining DevOps: The Transformative Power of Containerization

    Partner Resources

    ×

    Comments
    Oops! Something Went Wrong

    The likes didn't load as expected. Please refresh the page and try again.

    ABOUT US

    • About DZone
    • Support and feedback
    • Community research
    • Sitemap

    ADVERTISE

    • Advertise with DZone

    CONTRIBUTE ON DZONE

    • Article Submission Guidelines
    • Become a Contributor
    • Core Program
    • Visit the Writers' Zone

    LEGAL

    • Terms of Service
    • Privacy Policy

    CONTACT US

    • 3343 Perimeter Hill Drive
    • Suite 100
    • Nashville, TN 37211
    • support@dzone.com

    Let's be friends:

    Likes
    There are no likes...yet! 👀
    Be the first to like this post!
    It looks like you're not logged in.
    Sign in to see who liked this post!