The two microservices you will deploy are called system
and inventory
. The system
microservice returns the JVM system properties of the running container. The inventory
microservice adds the properties from the system
microservice to the inventory. This demonstrates how communication can be established between pods inside a cluster. To build these applications, navigate to the start
directory and run the following command.
cd start
mvn clean package
Next, run the docker build
commands to build container images for your application:
docker build -t system:1.0-SNAPSHOT system/.
docker build -t inventory:1.0-SNAPSHOT inventory/.
The -t
flag in the docker build
command allows the Docker image to be labeled (tagged) in the name[:tag]
format. The tag for an image describes the specific image version. If the optional [:tag]
tag is not specified, the latest
tag is created by default.
Run the following command to deploy the necessary Kubernetes resources to serve the applications.
kubectl apply -f kubernetes.yaml
When this command finishes, wait for the pods to be in the Ready state. Run the following command to view the status of the pods.
When the pods are ready, the output shows 1/1
for READY and Running
for STATUS.
NAME READY STATUS RESTARTS AGE
system-deployment-6bd97d9bf6-6d2cj 1/1 Running 0 34s
inventory-deployment-645767664f-7gnxf 1/1 Running 0 34s
After the pods are ready, you will make requests to your services.
The default host name for Docker Desktop is localhost
.
The default host name for minikube is 192.168.99.100. Otherwise it can be found using the minikube ip
command.
Navigate to http://[hostname]:31000/system/properties
and use the username bob
and the password bobpwd
to authenticate. Replace [hostname]
with the IP address or host name of your Kubernetes cluster. Open your browser’s developer console and examine the response headers.
You can also run the curl
command to make requests to your microservices. Use the -u
option to pass in the username bob
and the password bobpwd
.
curl http://localhost:31000/system/properties -u bob:bobpwd
If the curl
command is unavailable, then use Postman. Postman enables you to make requests using a graphical interface. To make a request with Postman, enter http://localhost:31000/system/properties
into the URL bar. Next, set the Authorization
with Basic Auth
type. Set the Username
field to bob
and the Password
field to bobpwd
. Read the Authorizing requests document for more details. Finally, click the blue Send
button to make the request.
curl http://localhost:31000/system/properties -u bob:bobpwd
curl http://$(minikube ip):31000/system/properties -u bob:bobpwd
Similarly, navigate to http://[hostname]:32000/inventory/systems/system-service
, or use the following curl
command to add the system to your inventory.
curl http://localhost:32000/inventory/systems/system-service
curl http://$(minikube ip):32000/inventory/systems/system-service