How to deploy a war file in a tomcat container pod and expose the service in GKE
In this post, we are going to see how to deploy a java war file inside a tomcat container pod and expose the endpoint as an external load balancer in google Kubernetes engine .
Usually in container microservices CI/CD — we check in the code to a source control repository , which triggers an webhook event and a build software like Jenkins will automatically triggers the pipeline in response to the commit to create jar / war file etc , then the pipeline pushes the build artifacts into an artifacts repository like Nexus, followed by creating the container image through Docker, which then gets stored into a container repository for final deployment as a Kubernetes workload. During this process, we also do additional steps like code quality inspection with tools like Sonarqube and vulnerability assessment of the final built container.
So In this post, we are not going to see any of the above steps.
This post is more on how to do the deployment from your local machine to GKE before a CI/CD pipeline setup is made.
Download gcloud SDK and configure it in your local machine. Run the below commands to get authenticated with your credentials.
gcloud auth application-default login
gcloud config set project "Projectid"
Enable the artifact registry api and create a sample folder in the region of your choice.
Register gcloud as the credential helper for all Google-supported Docker registries. If the Docker configuration already contains a credHelper entry, it will be overwritten.
gcloud auth configure-docker us-central1-docker.pkg.dev
Create a docker file , based on your application type. Here we are using a war application which will be deployed inside a tomcat container. We use a minimal version of tomcat alpine image for container build. Make the application to listen on port 8080 inside the container.