In this tutorial we are going to walk through step by step for running a Spring Boot application on google kubernetes engine (GKE).
This article assumes that you have a domain registered. Basic understanding of docker, kubernetes and google cloud is also expected.
Code samples are available in our github repository. We will use that as our app to deploy on kubernetes. This app uses gradle as build tool and we are using google cloud.
- Create a spring boot application
We have uploaded a sample app on github:
2. Build a docker container for the app.
To build docker run
This will create a docker image with tag k8scale-springboot-example:1.0-SNAPSHOT
You can upload the docker image to gcr using:
3. Create a kubernetes cluster in GKE.
Lets name our cluster “k8scale-springboot-example-us-east1”
gcloud container clusters create k8scale-springboot-example-us-east1
4. Point your kubectl to the gke cluster.
gcloud container clusters get-credentials k8scale-springboot-example-us-east1
5. Deploy app to cluster
Lets write a simple deployment yaml to deploy our app on the cluster created.
Check the repository for a sample file. Run
kubectl apply -f <FileName>
6. Expose your service
Once the service is created we need to expose the service. Below is an example of this.
7. Link your existing domain
Create an external IP address and update you DNS record for your domain to point to the above IP address
gcloud compute addresses create k8scale-springboot-example-ipaddress --global
8. Setup Ingress
Once we have service up and running we need to setup ingress which would be taking traffic from the internet and forwarding to your backend service.
Park the question about line: we will cover later.
9. Done !
Once you have your ingress working , you can hit your domain in the browser and you should be able to access your service.
Well, we do not want to serve anything on http do we, so follow the next steps to enable https.
10. HTTPS certificate
Now let’s attach a certificate to our ingress so that we can access the service on https. We are going to use Google Managed Certificates for this:
And we are done !
Contact us if you need help with any specific step or anything in general about kubernetes.
If you want us to write a tutorial about any specific use case, do let us know and we can help out.