Data Management Global

 View Only

Deploying Db2 .NET Core application on Red Hat Openshift environment

By Hosathota Vishwanatha posted Thu December 02, 2021 05:38 AM

By following few simple steps as detailed below, a simple Db2 .NET Core application can be deployed on Red Hat Openshift environment.

1. First create a simple .NET Core 3.1 Console application in Visual Studio and name it as DockerTester

2. Set the project configuration to x64.

3. Using Manage Nuget Packages option in the project, add IBM.Data.DB2.Core-lnx, the Db2 .NET Core package for linux

4. Next add a docker file into the project and include following code in it
#See to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM AS base

#Setting LD_LIBRARY_PATH is critical for Db2 .NET driver to work and setting it like below works for normal docker scenario
#but it has to be set through Build Configs in Openshift environment as detailed later
#ENV LD_LIBRARY_PATH="/app/clidriver/lib"
#ENV LD_LIBRARY_PATH="/app/bin/x64/Debug/netcoreapp3.1/clidriver/lib"

RUN apt-get -y update && apt-get install -y libxml2

FROM AS build
COPY ["DockerTester.csproj", "."]
RUN dotnet restore "./DockerTester.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "DockerTester.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "DockerTester.csproj" -c Release -o /app/publish

FROM base AS final
COPY --from=publish /app/publish .

#Env PATH=$PATH:"/app/bin/x64/Debug/net5.0/clidriver/bin:/app/bin/x64/Debug/net5.0/clidriver/lib"
Env PATH=$PATH:"/app/bin/x64/Debug/netcoreapp3.1/clidriver/lib:/app/bin/x64/Debug/netcoreapp3.1/clidriver/lib"

ENTRYPOINT ["dotnet", "DockerTester.dll"]

5. As indicated in the comment section in the above docker file, setting of LD_LIBRARY_PATH has no effect on Openshift containers and it has to be set through Build Config inside Openshift project.

6. Put the above code into a git repository. As an example the following public git repository has a simple console application

7. Now login to AWS Openshift cluster and Add an application. For this example since we have already created a project in git, lets choose the git option as shown below

8. Specify the Git repository and choose .NET as the template to create application. The example uses the sample repository  Ideally the code should come from a local repository and it should have appropriate code.

9. Select .NET Core 3.1 RHEL image and specify an application name.

10. We need to provide one critical configuration at this stage and that is to make a build configuration entry to set the LD_LIBRARY_PATH.

11. Click on the Build configuration to open the Build Configuration dialog.
The value specified for LD_LIBRARY_PATH is based on the location of the clidriver inside the deployed container. If it is different from the above, please specify the appropriate path. Click on the Create option to create the application.

12. The created application will be visible in the Topology view with three circles to build/edit code/see the output

13. Click on the application at the center of the above screen to see further options for this application. Use the Start Build option to build the image anytime. The image will be built using the code from the specified repository. In case of any build error it will be displayed at the right hand side.

14. If a build is successful, the build status and Pod status will be displayed above the Start Build option.

15. In case of any Pod error, click on the View Logs option to open the log file

16. Since the code is in public git, the actual server details are missing and it is resulting in a Pod crash.

​​​​​At Step 8 above, by providing a correct repository with working code in it, the steps detailed above can be followed to deploy a Db2 .NET Core application into Red Hat Openshift environment.

The above steps are for detailing the minimum configuration needed to deploy a sample db2 .NET Core application to Openshift environment. Further configuration or deployment options are not covered in this example.




Fri January 06, 2023 05:47 AM

Can we use the driver IBM Data Server Driver for ODBC and CLI (Linux AMD64 and Intel EM64T) - in the docker container for our Dot Net Core application to connect connect DB2 v11.5 Database on ZOS . If yes, can you please provide steps or sample docker file to use it?

Wed September 14, 2022 12:42 AM

If we are using S2I for build, how will we update the PATH?