Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content
Announcements
Qlik Connect 2025! Join us in Orlando join us for 3 days of immersive learning: REGISTER TODAY

Containerization and orchestration of Talend microservices with Docker and Kubernetes

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
TalendSolutionExpert
Contributor II
Contributor II

Containerization and orchestration of Talend microservices with Docker and Kubernetes

Last Update:

Jan 22, 2024 9:35:30 PM

Updated By:

Jamie_Gregory

Created date:

Apr 14, 2021 5:35:39 PM

This article shows you how to deploy a containerized microservice on a Kubernetes platform using Jenkins.

The article covers:

  • Microservices structure an application into several modular services
  • Containers are a good way to develop and deploy microservices, and the platforms for running containers are a good way to manage microservice-based applications
  • Docker is an open-source platform that is used to create, deploy, and run applications by using containers
  • Kubernetes is an open-source system for automating deployment, scaling, and the operations of application containers across clusters of hosts

This is a continuation of the Talend Community Knowledge Base article, Continuous Integration and Continuous Deployment of data services, routes, and microservices.

Sources for the project are available in the attached Zip file.

Prerequisites

Install the software and configure the servers:

  1. Create three VMs and install Ubuntu Linux 18.04.

  2. Name the servers ciserver, adminserver, and executionserver respectively.

    In the /etc/hosts file, map the domain name of the server to the given IP address.

    sudo vi /etc/hosts
    ## Execution server settings ##
    192.168.238.3        executionserver
    ## Admin server settings ##
    192.168.238.5        adminserver
    ## CI server settings ##
    192.168.238.3        executionserver 
    192.168.238.4        ciserver
    192.168.238.5        adminserver
  3. On the ciserver, install the following:

    • OpenJDK Zulu-8
    • Jenkins
    • Talend CommandLine
    • Latest patches for Talend CommandLine and Studio

  4. On the adminserver, install the following:

    • OpenJDK Zulu-8
    • Nexus
    • Talend Administration Center
    • Talend Studio
    • Install Git and create a repository, for example, CI_ESB_DEMOS

  5. On the executionserver, install the following:

    • Docker
    • Microk8s (single node Kubernetes cluster with Docker and built-in registry)

Note:

  • Steps in this article require minimal knowledge of Docker and Kubernetes.

  • Steps in this article can be executed on any Linux OS.

  • For information on installing Talend Software modules on the adminserver, see Talend Data Services Platform Installation Guide for Linux on the Talend Help Center.

  • For information on installing Docker and Kubernetes on Ubuntu, see the Microk8s documentation.

 

Containerization of Talend microservices

Fabric8 Maven plugin (f8-m-p)

The fabric8-maven-plugin (f8-m-p) supports multiple configuration models to create Docker images and Kubernetes resources descriptors for Java applications. This tutorial leverages two popular models:

  • XML Configuration
  • Resource Fragments (external configuration files)

For more information on configuration models, see the Maven fabric8-maven-plugin documentation, and scroll down to the Configuration section.

Building Docker images using XML Configuration

f8-m-p provides an XML-based configuration for creating Docker files or to include external Docker files and assemble the Java build into a Docker image.

With Talend Studio, the Docker profile build and push goals are invoked during the Maven deploy phase.

  • Build artifacts (Talend Jobs) and assemble the build into a Docker image. The Docker image name can be specified with the <name> tag.

  • Push uploads the image to a registry.

0693p000008uI97AAE.jpg

Generating Kubernetes resources using XML Configuration

Using XML Configuration, you can create Kubernetes API objects, such as labels, secrets, and services.

0693p000008uI9HAAU.jpg

Generating Kubernetes resources using Resource Fragments

Resource fragment models allow expert users to use plain configuration files, such as YAML. A YAML file specifies a skeleton and allows you to create complex Kubernetes / OpenShift API objects. F8-m-p can resolve a Maven XML configuration, pick up the resource files, and further enrich the configuration into a single kubernetes.yml and openshift.yml file.

The flowchart shows you how f8-m-p generates Kubernetes resource descriptors.

0693p000008uI9MAAU.jpg

Objectives and logical architecture

  1. Configure Jenkins for Docker and Kubernetes integration

  2. Create a pipeline Job that builds a microservice as a Docker image, then publishes it to the Docker registry

  3. Change Talend Studio plug-in

  4. Create a new Maven profile with XML Configuration

  5. Use Resource Fragments or external resources (YAML files)

  6. Create a pipeline Job that builds a microservice as a Docker image, generates Kubernetes resources, and finally deploys the service to a Kubernetes engine

  7. Verify the deployment using Kubectl commands and from Kubernetes dashboard

    0693p000008uHtBAAU.jpg

     

Configuring Jenkins for Docker and Kubernetes integration

Jenkins needs additional tools and configurations to generate Docker images and a Kubernetes deployment. To accomplish this, you will do the following:

  1. Use Manage Plugins to install additional plug-ins for Docker

  2. Configure System parameters, for example, Docker registry and Kubeconfig

  3. Configure Credentials, for example, Docker

 

Manage Plugins

  1. In the Manage Jenkins view, select Manage Plugins.

  2. Select the Available tab.

  3. Select and install the Docker plug-in.

  4. Install the core plugins as described in the Continuous Integration and Continuous Deployment of data services, routes, and microservices article of this series.

Configure System

  1. In the Manage Jenkins view, click Configure System and configure your system variables and Docker registry settings.

  2. Configure the KUBECONFIG environment variable that allows Jenkins to communicate with a Kubernetes cluster on a remote server.

    1. Log in to the executionserver.

    2. Copy the kubelet.config file of the Microk8s Kubernetes instance.

      Note: In Microk8s the kubelet.config file is located at /snap/microk8s/current/microk8s-resources.

      In Minikube the config file is located at ~/.kube/config.

    3. Log in to the CI server as Jenkins user.

    4. Copy the kubelet.config file from the Jenkins home folder, for example, /var/lib/jenkins.

      0693p000008uI9RAAU.jpg

       

  3. Navigate to Pipeline Model Definition to configure the Docker registry URL and credentials.

    Note: Follow the steps in Continuous Integration and Continuous Deployment of data services, routes, and microservices and configure your Docker registry credentials.

    0693p000008uI9WAAU.jpg

     

  4. Configure the environmental variable, as described in the Continuous Integration and Continuous Deployment of data services, routes, and microservices article of this series.

Creating a Jenkins Job: build a microservice Docker image and publish to Docker registry

  1. Click New Item, enter the name of the pipeline, for example, Pipeline_DemoRestRoute_Docker, then click Pipeline and click OK.

    0693p000008uI9gAAE.jpg

     

  2. In the Description field, provide the purpose of this pipeline.

    0693p000008uI9lAAE.jpg

     

  3. Click Build Triggers, select Poll SCM, for example, every night.

    0693p000008uI9qAAE.jpg

     

  4. Click Pipeline, then select pipeline script from the Definition drop-down menu. Copy the contents of the groovy script, Pipeline_k8s_deploy.groovy, attached to this article, into the script area.

    0693p000008uI9vAAE.jpg

     

    Observe:

    • Value of DOCKER_HOST environment variable is set with the URL of the Docker daemon which is running on the execution server.

    • Maven profile used, for example, -pdocker.

    • Docker CLI options, for example, -Ddocker.push.username.

  5. Save the file, then click Build now.

  6. Verify the run in the Blue Ocean pipeline.

  7. After successful execution, the pipeline status turns to green.

    0693p000008uIA5AAM.jpg

     

  8. Verify that the image is created in the Docker registry.

    0693p000008uHPoAAM.jpg

     

  9. Log in to the executionserver and verify the image, using the following command:

    docker images

    0693p000008uIAFAA2.jpg

     

  10. Run the container msdemorestroute, using the following command:

    docker run -p 8065:8065 msdemorestroute

    0693p000008uIAKAA2.jpg

     

  11. Test the microservice, by typing the following URL into your browser.

    http://executionserver:8065/services/customers

    0693p000008uIAPAA2.jpg

Configuring Talend Studio for generating Kubernetes resources

Create a new Maven profile, called k8s, with the XML Configuration model to store Docker images and Kubernetes resource objects. The k8s profile should execute resource, push, and deploy goals during the Maven deploy phase.

  • Resource creates Kubernetes and OpenShift resource descriptors leveraging XML Configuration and resource fragments models.
  • Push uploads the image specified in the <name> tag to a registry.
  • Deploy applies Kubernetes resource descriptors to the cluster and deploys the containerized microservice.

    0693p000008uI4SAAU.jpg

     

Creating a new Maven profile k8s

  1. Connect to Talend Studio remote Project.

  2. Click File > Edit project properties to open the Project Settings dialog box.

  3. Select Build > Maven > Default from the navigation menu on the left, to open the Project POM settings.

    Note: Backup the original POM settings before making any changes.

  4. Search for the Maven profile ID, docker, in the Project POM settings.

  5. Append the new profile, k8s, in the profile_k8s.xml file attached to this article, after the docker profile.

Including external files or Resource Fragments

In this article, external descriptors are stored in a Git repository, for example, CI_ESB_DEMOS. Jenkins can check out the Kubernetes resources along with the Talend project.

0693p000008uIAUAA2.jpg

 

  1. Create two files for resources, Deployment.yml and Service.yml. Both files in the ZIP file attached to this article.

    0693p000008uIAZAA2.jpg

     

  2. Notice the mapping to the external resources file with XML element <resourceDir>, in the k8s profile shown below:

    0693p000008uIAeAAM.jpg

     

  3. Review the contents of the deployment.yml file.

    0693p000008uI5bAAE.jpg

     

  4. Review the contents of the service.yml file.

    0693p000008uIAjAAM.jpg

     

Creating a Jenkins pipeline: build a microservice Docker image and deploy to a Kubernetes engine

  1. Click New Item, enter the name of the pipeline, for example, Pipeline_Microservice_DemoRestRoute_Docker_k8s, click Pipeline, then select the pipeline you created in the previous step. Click OK.

    0693p000008uI7lAAE.jpg

     

  2. Update the Description of the pipeline.

    0693p000008uIAoAAM.jpg

     

  3. Click Pipeline, then select pipeline script from the Definition drop-down menu. Copy the contents of the groovy script, Pipeline_docker_register_deploy.groovy, attached to this article, into the script area.

    0693p000008uI5QAAU.jpg

     

  4. Click Build now and run the pipeline.

  5. Click the pipeline and observe the generated artifacts.

    0693p000008uI9SAAU.jpg

     

Testing the containerized microservice on the Kubernetes platform

Using Kubernetes dashboard

  1. Log in to the executionserver.

  2. In Microk8s, install the Kubernetes dashboard, by entering the following command:

     microk8s.enable dns dashboard 
  3. Get the ClusterIP and Port of the kubernetes-dashboard service, by issuing the below command:

    kubectl get svc --all-namespaces

    0693p000008uHdwAAE.jpg

  4. To see the dashboard; type the following URL into your browser, then accept any security exceptions, and skip the security settings

    https://CLUSTER-IP:443/
  5. From the dashboard, navigate to the Overview screen, then review the status of Deployments, Pods, Replica sets, Services, and Secrets.

    0693p000008uIAyAAM.jpg0693p000008uI8oAAE.jpg

Using Kubectl commands

  1. Log in to the executionserver.

  2. Verify the status of your Deployments, by using the kubectl command along with a label, in this case, -l environment, as shown below:

     kubectl get deployments -l environment -o wide
  3. Verify the response from the kubectl command, and observe the Selector, in this case, environment=dev.

    0693p000008uIB3AAM.jpg

  4. Get the ClusterIP and Port, by entering the following command:

     kubectl get svc -l environment=dev
  5. Open a browser window on the executionserver and call the microservice with Cluster-IP, as shown below:

    https://CLUSTER-IP:SERVICE-PORT/

    0693p000008uIAuAAM.jpg

  6. Get the pod or container IP, by entering the following command:

     kubectl get pods -l environment=dev -o wide 
  7. From a browser window on the executionserver, call the microservice with Container-IP and ContainerPort, as shown below:

    https://CONTAINER-IP:CONTAINER-PORT/services

    0693p000008uI0LAAU.jpg

Configuring Liveness and Readiness probes

Talend microservices supports JMX and Spring Actuator that enables you to monitor the health of the service using the context path, /health. In a containerized environment health checks help you to identify the health of the Container or Pod and determine when to restart the Container.

  1. Using the Pod IP and port 8080 check the health of the service.

    http://POD_or_CONTAINER_IP:8080/health

    0693p000008uHuUAAU.jpg

     

  2. On the Overview screen, click Deployments, select the ellipsis to the right of msdemorestroute. In the Scale a Deployment dialog box set the Desired number of pods to 0. Click OK.

  3. Notice that the running Pod or the Container is undeployed and the count changes to 0.

    0693p000008uIB8AAM.jpg

     

  4. From the Overview screen, click Deployments > View/edit YAML, and change the initialdelayseconds to 1, then click Update.

    0693p000008uIA6AAM.jpg

     

  5. From the Overview screen, click Deployments, and set Scale a Deployment to 1. Click Update. After the update, notice that the health of Deployments and Pods has changed to red.

    0693p000008uIBDAA2.jpg

    The Container status changed to red, and the Readiness Probe failed because the Container is still in Creation mode, because the configuration of initialdelayseconds that is set to 1.

     

  6. The next health check is done again after a delay of 10 secs.

  7. Now if the Container is up, the status turns green.

 

Frequently Asked Questions

Question: Why use two configuration models to generate resource descriptors?

Answer: The XML Configuration model allows for type-safe configuration with IDE support. However, it only allows you to configure a subset of possible Kubernetes resource descriptors. For example, the XML Configuration model doesn't allow you to configure the resource descriptors for all API objects, such as, Deployments and Selectors.

Question: Can I build a Docker image using external Docker files?

Answer: Yes. In the <image> element you can refer to external Docker files with the elements dockerFile and dockerFileDir.

Question: Can I create or configure a Secret for sensitive information like credentials?

Answer: Yes. The <secret> element can be configured using XML Configuration or Resource Fragments.

Question: Can I add labels with XML Configuration?

Answer: Yes. Use the <resources> element to add labels, for example:

The <all> element allows you to create a label on all resource objects, such as Pods, Services, Deployments, and Replicasets.

The name and value of the labels can be passed dynamically from the Jenkins Job, labels such as environment = dev and module = xyz.

Question: Which additional features are brought in by Enrichers?

Answer: Enrichers are used to create and customize Kubernetes and OpenShift resource objects. They are looked up automatically from the plug-in dependencies and the add more features to the generated skeleton. For example, it adds health checks for spring boot microservices if the spring-boot JAR is present as a dependency.

Question: Can I include or exclude a set of Enrichers?

Answer: Yes. The element <enrichers> excludes labels from fmp-project and adds default labels like artifactId, groupid, version, and provider.

Question: How are the health checks performed on a containerized microservice?

Answer: Enricher f8-healthcheck-spring-boot generates resource descriptors for performing Kubernetes Liveness and Readiness probes on spring-boot containers.

Conclusion

In this article, you leveraged Talend Studio and the f8-m-p plug-in to create Maven profiles for Docker and k8s. You created a Docker image and generated Kubernetes resources for a microservice, then with a Jenkins pipeline script, you published the microservice container to a Docker registry and deployed Kubernetes resources to a Kubernetes engine. Finally, you tested the microservice with Container IP, Cluster IP, and verified Liveness and Readiness probes.

Labels (2)
Version history
Last update:
‎2024-01-22 09:35 PM
Updated by: