Hello Server
You will need Docker and Java JDK installed to run this sdemo.
-
OpenJDK is available here: https://www.azul.com/downloads/zulu.
- Scroll down to Zulu CommunityTM Downloads
- Enter Java version, your platform and processor size.
-
Docker for Desktop is an easy option for Windows o MAcOS and has a one-click option to run Kubernetes as well.
Run as an Application
-
To build:
Windows: mvnw package Linux: ./mvnw package
-
Should create an executable jar in
target/
. Run it:java -jar target/hello-server-1.0.0.jar
-
Then either
- Open your browser to http://localhost:8080 - returns JSON, so best viewed using the JSON add-on for your browser
- Or, in a second CMD/Terminal window invoke
curl http://localhost:8080
IMPORTANT: Stop the application once you are satisfied it is working to free up port
8080
.
Run Using Docker
-
You might like to view the
Dockerfile
first to see what it configures. -
Create a docker container (where docker-id is your Docker Hub id. If you don't have one, just use your first name):
docker build -t <docker-id>/hello-server .
-
Check it exists - it should be in this list:
docker images
-
To run:
docker run --name hello-server -p8080:8080 <docker-id>/hello-server
You should see Spring output to the console as it runs.
-
Again access http://localhost:8080 to check it's working
IMPORTANT: Hit CTRL-C to stop the container to free up port
8080
.
Run Using Kubernetes
-
To put your image up at Docker Hub, you need to run
docker push <docker-id>/hello-server
.- However if you don't have a docker hub account or upoloading the image is too slow, you can use one I created earlier
paulc4/hello-server
.
- However if you don't have a docker hub account or upoloading the image is too slow, you can use one I created earlier
-
Make sure
kubectl
is pointing at your Kubernetes cluster. -
Create a dedicated namespace
kubectl create namespace hello
-
Make it your default:
kubectl config set-context <cluster-name> --namespace=hello
-
If you wish to use the image you just pushed, edit
hello-server.yaml
and changepaulc4
to yourdocker-id
, assuming you called the image<docker-id>/hello-server
. -
Deploy the web server:
kubectl apply -f hello-server.yaml
-
What have we deployed:
kubectl get pods kubectl get deployments
-
Go to Kubernetes dashboard, select
hello
namespace and view the pods. -
Expose the web-service:
kubectl expose deployment hello-server --type=LoadBalancer --port=8080 --target-port=8080
-
To see what IP-address was allocated to the application:
kubectl get services -n paul
. The output looks like:$ kubectl get services NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-server 10.3.245.61 104.155.111.170 8080:32452/TCP 2m
The external IP may be a DNS name (for example if your cluster is on AWS).
-
Access
http://<external-ip>:8080
to check it's working
Help
Reference Documentation
For further reference, please consider the following sections:
- Docker for Desktop
- Official Apache Maven documentation
- Spring Boot Maven Plugin Reference Guide
- Spring Web
Spring Guides
The following guides illustrate how to use some features concretely: