Deploy Springboot to GKE from scratch in 7 minutes

> Google Kubernetes Engine

Google Kubernetes Engine known as GKE is an enterprise-grade platform for containerized applications, including stateful and stateless, AI and ML, Linux and Windows, complex and simple web apps, API, and backend services. Leverage industry-first features like four-way auto-scaling and no-stress management. Link


  • Maven / Gradle
  • mvnw or gradlew
  • docker
  • kubenetes
  • Google cloud account
  • IDEA I prefer IntelliJ

> Initial Springboot

Go to to initialze your project

Initializr springboot project
Import project / project structure
// GkeApplicationTests@ExtendWith(SpringExtension.class)
class GkeApplicationTests {

GkeApplication app;

private MockMvc mvc;

public void setUp() {
app = new GkeApplication();
mvc = MockMvcBuilders.standaloneSetup(app)

@DisplayName("Test get hello with PathVariable success")
void testGetHelloWithPathVariableSuccess() throws Exception {
MvcResult mvcResult = mvc.perform(get("/hello/Gique"))
.andExpect(content().string("Hello Gique"))
// GkeApplication@SpringBootApplication
public class GkeApplication {

public static void main(String[] args) {, args);

public String hello(@Valid @PathVariable("name") String name) {
return "Hello " + name;

> Docker

For this step, I will lead you to create simpleDockerfile as below

// DockerfileFROM openjdk:8
RUN mkdir /application
COPY . /application
WORKDIR /application
RUN /application/mvnw install #if you use gradle change it to /application/gradlew build
RUN mv /application/target/*.jar /application/app.jar
ENTRYPOINT ["java","","-jar","/application/app.jar"]

> Google Cloud Platform

Therefore, when you wanna use GKE you must have GCP account. This section, I will lead you to create a project on Google Cloud Platform (GCP).
Go to and click create new project

Create new project

Container Registry

Go to Container Registry then click Enable

Enable container registry
gcloud auth login
// Go to your project directory 
$ cd /Users/${your_account}/Project/gke/
$ gcloud builds submit .
Push image to Container Registry success
docker image on Container Registry

Kubernetes Cluster

Earlier we created image file for running on production.
Now, we need to create a cluster because Google Kubernetes Engine lets you create Kubernetes clusters to host. Let’s go to Console Kubernetes to Enable Kubernetes Engine API

Enable Kubernetes Engine API
// Command
$ gcloud container clusters create gke-application-demo-cluster --num-nodes=3 --region=asia-southeast1-a
$ gcloud config set container/cluster gke-application-demo-cluster
cluster gke-application-demo-cluster

Deploy to Kubernetes Cluster

Congratulations, It’s almost complete already. So, this section will lead you to deploy your image to Kubernetes Cluster.

$ kubectl run gkeappdemo --port 8080$ kubectl get pods$ kubectl expose deployment gkeappdemo --type=LoadBalancer --port 80 --target-port 8080$ kubectl get service
Compute Engine and Kubernetes clusters
Congratulations!! you can do it.

Update your application

When you have any changes you can push new image anytime.

$ gcloud builds submit .$ kubectl set image deployment/gkeappdemo$ kubectl get service
gkeappdemo version 2
kubectl set image deployment/gkeappdemo

> Conclusion

Actually, This is some of many method to deploy your image to GKE. There are many ways to deploy to GKE such as Cloud Code in IntelliJ which you can use it also.



Get the Medium app

Sakul Montha

Sakul Montha

Development Director, a man who’s falling in love with the galaxy.