- Log on to the cluster using the
occlient
oc login https://api.cluster-b1c8.b1c8.sandbox941.opentlc.com:6443 -u user1 -p r3dh4t1!
- Create a new namespace
oc new-project demo
- Create a directory named demo and subsequently enter in
mkdir demo && cd demo
- Create a
pom.xmlfile and add the following content:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2016-2017 Red Hat, Inc, and individual contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.fruitsand</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Spring Boot - Demo</name>
<description>Spring Boot - Demo</description>
<packaging>pom</packaging>
<modules>
<module>fruit-backend-sb</module>
<module>fruit-client-sb</module>
</modules>
</project>
- Create a new client project using the REST HTTP
clienttemplate proposed by the scaffolding tool:
hal component spring-boot \
-i fruit-client-sb \
-g me.fruitstand \
-p me.fruitstand.demo \
-s 2.1.6.RELEASE \
-t client \
-v 1.0.0-SNAPSHOT \
--supported=false \
fruit-client-sb
./create-backend
- Create a backend project interactively and use as template the
crudtype andfruit-backend-sbas maven project name:
hal component spring-boot fruit-backend-sb
Build the project
7. Compile and generate the uber jar of the Spring Boot application client
mvn package -f fruit-client-sb
- Repeat the command executed previously for the CRUD - backend microservice.
mvn package -f fruit-backend-sb -Pkubernetes
- Create the component in the cluster
hal component create -c fruit-client-sb,fruit-backend-sb
- push the jars
hal component push -c fruit-client-sb,fruit-backend-sb
- Check if the components have been correctly installed
oc get cp
- Create a capability to install a PostgreSQL database using the interactive mode
hal capability create
- Check the capability status
oc get capabilities
- Link the microservices
We need to wire thefruit-backend-sbcomponent with thepostgres-dbcapability by creating a link between both
hal link create
? Target component: fruit-backend-sb
? Use Secret Yes
? Secret [Use arrows to move, space to select, type to filter]
deployer-token-8jg7f deployer-token-g2nh2 postgres-capability-156813480542327300-bba890eb-dockercfg-zljff> postgres-capability-1568134805423273000-config
? Change default name fruit-backend-sb-link-1568136120947947000
✓ Created link fruit-backend-sb-link-1568136120947947000
- Now, create a link targeting the
fruit-client-sbcomponent to wire the client and backend
hal link create
? Target component: fruit-client-sb
? Use Secret No
? Env variable in the 'name=value' format, press enter when done KUBERNETES_ENDPOINT_FRUIT=http://fruit-backend-sb:8080/api/fruits
Set env variable: KUBERNETES_ENDPOINT_FRUIT=http://fruit-backend-sb:8080/api/fruits
? Env variable in the 'name=value' format, press enter when done
? Change default name fruit-client-sb-link-1568136198776371000
✓ Created link fruit-client-sb-link-1568136198776371000
- Check the link status:
oc get links
- Try the backend service to see if it works
Access to the backend in a browser and create some fruits
oc get routes/fruit-client-sb --template={{.spec.host}}
Copy/paste the address displayed within the terminal in a browser and create some fruits ;-)
- Try the client microservice to see if it works too
So, get also its route address using this commandoc get routes/fruit-client-sb --template={{.spec.host}}
and curl the service within your terminal, you should get the fruits created in the previous step.
FRONTEND_URL=$(oc get routes/fruit-client-sb --template={{.spec.host}})
curl "http://${FRONTEND_URL}/api/client"