Spring Boot is a great way to write an application in Java. This scenario shows you how to create a Spring Boot application and run it in Kubernetes with as little fuss and bother as possible. And there's no YAML. To do this we need to do three things:
- Create a Spring Boot application
- Containerize it, and push the container to a registry
- Deploy it to Kubernetes
You will need a few minutes of time. If you have credentials for a public docker registry, like Dockerhub or Google Container Registry, that will help, but it won't stop you from completing the scenario.
We also don't cover all the options available for building containers. There is a Spring Boot topical guide covering some of those options in more detail.
When it comes to deploying the application to Kubernetes, there are far too many options to cover them all in one tutorial. We can look at one or two, but the emphasis will be on getting something working as quickly as possible, not on how to deploy to a production cluster.
Install and Run Kubernetes
Before you can start, you need to install and start the Kubernetes cluster.
Kubectl is the command line for Kubernetes. You can install it from Google storage:
curl -Lo /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v1.15.3/bin/linux/amd64/kubectl && chmod +x /usr/local/bin/kubectl
Create a Cluster with Kind
Kind is a tool for running Kubernetes in docker. It works well for integration testing, or for simple development-time use cases, where resources are constrained. You can install it from github:
curl -Lo /usr/local/bin/kind https://github.com/kubernetes-sigs/kind/releases/download/v0.5.1/kind-linux-amd64 && chmod +x /usr/local/bin/kind
and run it to create a (single node) Kubernetes cluster:
kind create cluster
Then set up the credentials to connect to to the cluster:
mkdir -p ~/.kube && kind get kubeconfig > ~/.kube/config
Check that it works:
kubectl get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 2d18h
Now we can deploy our Spring Boot application.