Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. READ MORE

How to schedule a Talend Job with Kubernetes

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

How to schedule a Talend Job with Kubernetes

Last Update:

Jan 22, 2024 9:35:30 PM

Updated By:

Jamie_Gregory

Created date:

Apr 1, 2021 6:19:48 AM

This article explains how to schedule a Talend Job as a Kubernetes Job and how to use Kubernetes as a Job orchestrator.

 

Sources for this project are available in the attached Zip files.

 

Talend Job

 

Configuration

  1. Create a Talend Job to generate random data and display it in the output console.

     

    0693p000008uA1KAAU.png

     

  2. Configure the tRowGenerator component as follows:

    • Identifier: A random value for each row

    • Firstname: A generated first name

    • Lastname: A generated last name

    • City: A generated city

  3. Specify the number of rows to generate using the context variable numRow, as shown in Figure 2. This helps you configure Jobs in Kubernetes.

     

    0693p000008u9t3AAA.png

     

    0693p000008uA1PAAU.png

     

You will find the Job Logrow 0.1 in the tlnd-job.zip file attached to this article.

 

Build

Before you can build a container image, you need to build the Job package. To build a Job, follow these steps:

  1. Right-click your Job, then select Build Job.

     

    0693p000008u9f0AAA.pngFigure 4: Build Job

  2. Keep the default configuration and click Finish.

     

    0693p000008uA1ZAAU.png

     

Configuring the Dockerfile

Now that you have a zip file containing your batch process, you need to configure a Dockerfile before you can build the Docker image. For this example, the Dockerfile and all other mentioned files are in the tlnd-k8s.zip file attached to this article.

 

The Dockerfile is composed of three sections:

  • Arguments
  • Java download
  • Job configuration

 

Arguments

This section contains all the arguments needed to configure the build.

 

0693p000008u9ikAAA.png

 

Java download

This section uses a multi-stage build, with a step dedicated to downloading a JRE. This download uses parameters from the arguments section.

 

0693p000008uA1jAAE.png

 

Job configuration

This section explains how to build the container image for your Job. You can split this section into multiple parts:

 

  • Arguments: map some of the parameters defined in the first section of the Dockerfile

    0693p000008u9sAAAQ.png

     

  • Labels: allow you to define and document your image

    0693p000008u9kFAAQ.png

     

  • Environment variables: provide information and help to configure the running process

    0693p000008uA23AAE.png

    In this example, the variable NUMROW allows you to configure the context variable numRow.

     

  • Installation: installs the JVM and your Job in a folder /opt/talend

    0693p000008u9TCAAY.png

     

  • Run User: the process runs as the user talend

    0693p000008uA2DAAU.png

     

  • Run command: the CMD runs the Job at each startup, using the environment variable NUMROW to overwrite the context variable

    0693p000008uA2IAAU.png

     

Once your Dockerfile is configured, copy the Logrow_0.1.zip file you generated earlier to the same folder, as shown below.

0693p000008u9uaAAA.png

 

Building the Docker image

  1. To build the image, run the following command in the folder where the Dockerfile and the zip file are located:

    docker build -t username/logrow:0.1.0 .

    Replace username with your Docker Hub username.

     

  2. At the end of the build process, you should see something like:

    Successfully built 6ef71caf6a90
    Successfully tagged username/logrow:0.1.0

     

  3. Test your images by running the following command:

    docker run --rm -i -e NUMROW=3 username/logrow:0.1.0

     

    0693p000008u9lhAAA.png

     

    0693p000008u9pkAAA.png

 

Pushing your Docker image

You need to push your images into a registry. This example uses a public Docker Hub. Replace username in the command below with your own username, or you will not be able to push your images.

docker push username/logrow:0.1.0

 

The second option, and the most common in many companies, is to use a private registry.

 

Configuring Minikube and Helm

 

Installation

This example simulates a Kubernetes cluster with Minikube, which runs a single node cluster hosted on a VirtualBox machine. To install Minikube see, Install Minikube on the Kubernetes documentation page.

 

Helm is a package manager for Kubernetes applications. It is very useful when you want to deploy multiple configurations as a single package. To install Helm see, Installing Helm on the Helm documentation page.

 

Initialization

To prepare the environment, you need to initialize Minikube and Helm.

 

Minikube

To initialize Minikube, type the following commands:

minikube start
minikube dashboard

 

You should see the Kubernetes dashboard:

 

0693p000008u9k6AAA.png

 

Helm

To initialize Helm, type the following command:

helm init

 

You should see this after the run:

$HELM_HOME has been configured at /Users/username/.helm.
Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.
Happy Helming!

 

Deploying your Job

You are ready to deploy your application. In this example, you are deploying a Kubernetes CronJob.

 

A cron job is a Job based on a schedule. To compare this to Talend Administration, it is a Job scheduled in the Job conductor.

 

This application is composed of two Kubernetes objects:

  • ConfigMap: a key/value object that contains the numRow context value

    This way, you are able to change the configuration of a Job without having to redeploy.

  • CronJob: contains your Talend Job container specifications

 

Understanding a Helm chart

A Helm chart is composed of multiple files that, once deployed, represent a release. In this example, you will deploy a package demo-job.

 

0693p000008u9uzAAA.png

 

The demo-job folder contains the following:

  • Chart.yaml: represents the definition of a chart
    0693p000008u9jlAAA.png

  • values.yaml: contains values for all variables used to configure your templates

     0693p000008u9yvAAA.png

 

In the folder templates, you have the configuration files for your Kubernetes objects:

  • configMap.yaml: creates a ConfigMap object that defines the value of the numRow variable. In the data section, use the key numrow to map to the container NUMROW environment variable.
    0693p000008u9rHAAQ.png

  • cronJob.yaml: contains the definition of the cron job deployment, such as the container to use and the mapping of the NUMROW environment variable to the configMap variable.

    0693p000008u9c9AAA.png

 

Deploying your Helm chart

  1. To deploy your chart, run the following command from inside the helm folder:

    helm install --name my-release --namespace talend ./demo-job

    This command contains:

    • --name my-release: configures the name of the release (replace my-release with desired release name)

    • --namespace talend: configures a new namespace called talend (replace as necessary)

    • ./demo-job: replace demo-job with the name of your package folder

     

    Result:

    NAME:   my-release
    LAST DEPLOYED: Mon Mar 26 16:32:57 2018
    NAMESPACE: talend
    STATUS: DEPLOYED
    
    RESOURCES:
    ==> v1/ConfigMap
    NAME                 DATA  AGE
    my-release-demo-job  1     0s
    ==> v1beta1/CronJob
    NAME                 KIND
    my-release-demo-job  CronJob.v1beta1.batch
    

     

  2. Verify that your objects were correctly deployed:

    0693p000008u9pHAAQ.png

     

    0693p000008u9wGAAQ.png

     

One thing to understand when you deploy a Cron Job:

  • A Cron Job is a scheduled Kubernetes object that is a Job. For each execution of a Job, Kubernetes creates a pod. The pod is where the container is running, and where you will be able to find logs.

     

    0693p000008uA2XAAU.png

     

    0693p000008u9vwAAA.png

     

    0693p000008u9fyAAA.png

If you want to change the number of rows generated, go into ConfigMap and change the value of numrow in my-release-demo-job.

Labels (1)
Comments
IPF
Contributor
Contributor

Great content!
would it be the same approach if the job is much more complicated (dealing with files, databases and API services)?
Keep sharing!

Xiaodi_Shi
Support
Support

Hello @IPF 

You are able to start/schedule the exported jobs as any script Shell using the standard cron or the scheduler of your choice. The Build Job feature allows you to deploy and execute a Job on any server, independent of Talend Studio.

For more information about your complicated job deployment, please feel free to ask a question on Forum.

Best regards

Sabrina

 

Version history
Last update:
‎2024-01-22 09:35 PM
Updated by: