Skip to content

Instantly share code, notes, and snippets.

@aureamunoz
Last active September 17, 2019 14:02
Show Gist options
  • Select an option

  • Save aureamunoz/efefa97e8594356f3c412635b6348680 to your computer and use it in GitHub Desktop.

Select an option

Save aureamunoz/efefa97e8594356f3c412635b6348680 to your computer and use it in GitHub Desktop.

Scenario steps

  1. Log on to the cluster using the oc client
oc login https://api.cluster-b1c8.b1c8.sandbox941.opentlc.com:6443 -u user1 -p r3dh4t1!  
  1. Create a new namespace
oc new-project demo  
  1. Create a directory named demo and subsequently enter in
mkdir demo  && cd demo
  1. Create a pom.xml file 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>
  1. Create a new client project using the REST HTTP client template 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
  1. Create a backend project interactively and use as template the crud type and fruit-backend-sb as 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
  1. Repeat the command executed previously for the CRUD - backend microservice.
mvn package -f fruit-backend-sb -Pkubernetes  
  1. Create the component in the cluster
hal component create -c fruit-client-sb,fruit-backend-sb  
  1. push the jars
hal component push -c fruit-client-sb,fruit-backend-sb  
  1. Check if the components have been correctly installed
oc get cp  
  1. Create a capability to install a PostgreSQL database using the interactive mode
hal capability create  
  1. Check the capability status
oc get capabilities  
  1. Link the microservices
    We need to wire the fruit-backend-sb component with the postgres-db capability 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

  1. Now, create a link targeting the fruit-client-sb component 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

  1. Check the link status:
oc get links  
  1. 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 ;-)

  1. Try the client microservice to see if it works too
    So, get also its route address using this command oc 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment