Introduction
In this article, you will understand how to transfer our existing tomcat application to run on Azure Kubernetes Service(AKS).

Pre-Migration
Before you begin, complete the assessment and inventory activities outlined in the following sections to ensure a successful migration.
Inventory external resources
Through the Java Naming and Directory Interface, external resources, including data sources, JMS message brokers, and others, are inserted (JNDI). Some of these resources might need to be relocated or reconfigured.
Inside your application
Examine the context.xml file under META-INF. Within the <Context> element, look for <Resource> elements.
On the application server(s)
Examine the.xml files located in the $CATALINA_BASE/conf/[engine-name]/[host-name] directories, as well as the $CATALINA_BASE/conf/context.xml and $CATALINA_BASE/conf/server.xml files.
JNDI resources will be described via the <Resource> components inside the top-level <Context> element in context.xml files.
The <Resource> elements in the <GlobalNamingResources> element in server.xml files will define JNDI resources.
Datasources
Make a note of the following details for each data source:
-
What's the name of the data source?
-
What is the configuration of the connection pool?
-
What location is the JDBC driver JAR file located?
All other external resources
We can't list all potential external dependencies in this tutorial. Your team is in charge of ensuring you can satisfy any external dependencies of your application following the move.
Inventory secrets
Passwords and secure strings

On the production server(s), search all properties and configuration files for any secret strings or passwords. Carefully look through the files in $CATALINA_BASE/conf called server.xml and context.xml. Inside your application, you could potentially discover configuration files that include passwords or other login information. META-INF/context.xml, applications.properties, or application.yml files are examples of possible candidates.
Determine whether the file system is used
Any use of the application server's file system requires configuration changes or, in rare circumstances, architecture changes. You may recognize any or all of the following circumstances.
Read-only static content
You'll need a different place for static content if your application currently delivers it. You might want to think about adding Azure CDN for lightning-fast downloads worldwide and migrating static material to Azure Blob Storage.
Dynamically published static content
Use Azure CDN and Azure Blob Storage, along with an Azure Function to handle uploads and CDN refreshes if your application permits static content uploaded or produced by your application but is immutable after it has been created.
Dynamic or internal content
You can connect Azure Storage shares as persistent volumes for files often written to and read by your application or static files that are only visible to your application.
Identify session persistence mechanism
Examine the context.xml files in your application and the Tomcat settings to determine the session persistence manager used. Find the Manager> element, then note the className attribute's value.
StandardManager and FileStore, two built-in PersistentManager implementations in Tomcat, aren't intended for usage with a distributed, scalable platform like Kubernetes. While AKS can transparently restart any pod at any moment and load balance across multiple pods, it is not advised to persist mutable state to a file system.
Use an alternative PersistentManager implementation that will write to an external data store, such as VMware Tanzu Session Manager with Redis Cache, if session persistence is necessary.
Special cases

Some production scenarios might call for more modifications or impose more restrictions. Even if they might not happen often, it's crucial to ensure they don't apply to your application or are handled properly.
Determine whether the application relies on scheduled jobs
Containerized Tomcat deployments cannot use scheduled tasks like cron jobs or Quartz Scheduler activities. One planned job may run more than once throughout a scheduled time if your application is scaled out. There may be unforeseen repercussions in this case. List all scheduled tasks, whether on the application server or not.
Determine whether AccessLogValve is used
If AccessLogValve is utilized, the mounted Azure Files share or one of its subdirectories should be specified as the directory parameter.
Parameterize the configuration
You probably saw secrets and external dependencies, such as datasources, in the server.xml and context.xml files during the pre-migration. Replace each username, password, connection string, or URL with an environment variable for each object that has been identified in this way.
Assume that the element shown below is present in the context.xml file:
<Resource
name="jdbc/dbconnection"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://postgresdb.contoso.com/wickedsecret?ssl=true"
type="javax.sql.DataSource"
username="postgres"
password="t00secure2gue$$"
/>
Change the above code to the following code:
<Resource
name="jdbc/dbconnection"
type="javax.sql.DataSource"
url="${postgresdb.connectionString}"
driverClassName="org.postgresql.Driver"
username="${postgresdb.username}"
password="${postgresdb.password}"
/>








