IBM/GameOn-Java-Microservices-on-Kubernetes

Name: GameOn-Java-Microservices-on-Kubernetes

Owner: International Business Machines

Description: This code demonstrates deployment of a Microservices based application Game On! on to Kubernetes cluster. Game On! is a throwback text-based adventure built to help you explore microservice architectures and related concepts.

Created: 2017-04-04 22:11:35.0

Updated: 2018-04-19 13:40:32.0

Pushed: 2018-05-10 21:20:53.0

Homepage: https://developer.ibm.com/code/patterns/deploy-java-microservices-on-kubernetes-with-polyglot-support

Size: 2676

Language: Shell

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

GameOn! Java Microservices on Kubernetes with polyglot ecosystem

Read this in other languages: ??????.

This code demonstrates deployment of a Microservices based application Game On! on to Kubernetes cluster which exists together with a polyglot ecosystem. Game On! is a throwback text-based adventure built to help you explore microservice architectures and related concepts. GameOn! deployment has two sets of microservice, core and platform. The core microservices are written in Java, coexisting with other polyglot microservices. In addition, there are platform services, which provide service discovery, registration and routing for different microservices. All run in in Docker containers managed by Kubernetes Cluster.

gameon

Core MicroServices:

There are five core Java microservices, using JAX-RS, CDI etc. part of the MicroProfile spec.

In addition, Proxy and WebApp complete the core microservices

Platform Services:
Prerequisite

To deploy the game locally, follow the instructions via docker-compose in GameOn repository here.

To follow the steps here, create a Kubernetes cluster with either Minikube for local testing, with IBM Cloud Private, or with IBM Bluemix Container Service to deploy in cloud. The code here is regularly tested against Kubernetes Cluster from Bluemix Container Service using Travis.

Steps
  1. Modify the Core services yaml files
  2. Create a Volume for your Cluster
  3. Create the Platform Services
  4. Create the Core Services
  5. Explore your GameOn App
  6. 5.1 Add Social Logins
  7. 5.2 Add Rooms
Troubleshooting

1. Modify the ConfigMap yaml file

Change these values on the gameon-configmap.yaml file. Change PLACEHOLDER_IP to the public IP of your cluster. You can get the IP from bx cs workers <your-cluster-name> for the Bluemix Container Service. Ex. 192.168.99.100

For minikube, you can get the IP using minikube ip

T_END_PLAYER_URL: https://PLACEHOLDER_IP:30443/players/v1/accounts
T_END_SUCCESS_CALLBACK: https://PLACEHOLDER_IP:30443/#/login/callback
T_END_FAIL_CALLBACK: https://PLACEHOLDER_IP:30443/#/game
T_END_AUTH_URL: https://PLACEHOLDER_IP:30443/auth

Y_DOCKER_HOST: 'PLACEHOLDER_IP'

An easy way to change these values is to do
sed -i s#PLACEHOLDER_IP#<Public-IP-of-your-cluster#g gameon-configmap.yaml
or sed -i '' s#PLACEHOLDER_IP#<Public-IP-of-your-cluster>#g gameon-configmap.yaml.

Then, apply the config map on your cluster:

bectl create -f gameon-configmap.yaml
igmap "gameon-env" created

2. Create a Volume for your Cluster

You would need to create a volume for your cluster. You can use the provided yaml file. The required keystores will be stored in this volume. The volume will also be used by the core services.

bectl create -f local-volume.yaml
istent volumes "local-volume-1" created
istent volumes "keystore-claim" created

You can now create the required keystores using the setup.yaml file. This will create a Pod and create the keystores.

bectl create -f setup.yaml

You can find the Dockerfile and script for generating keystore in containers/setup/ folder. You can build your own image using the provided Dockerfile.

Once it is done, the Pod will not run again. You can delete the Pod after using kubectl delete pod setup (optional).

If you want to confirm that the Pod has successfully imported the keystores, you can view the Pod's logs.

bectl logs setup
king for keytool...
king for openssl...
rating key stores using <Public-IP-of-your-cluster>:30443
ificate stored in file <keystore/gameonca.crt>
ificate was added to keystore
ificate reply was installed in keystore
ificate stored in file <keystore/app.pem>
verified OK
ificate was added to keystore
y for alias <*> successfully imported.

y for alias <**> successfully imported.
rt command completed:  104 entries successfully imported, 0 entries failed or cancelled

3. Create the Platform Services

You can now create the Platform services and deployments of the app.

bectl create -f platform
lternatively
bectl create -f platform/controller.yaml
bectl create -f platform/<file-name>.yaml

bectl create -f platform/registry.yaml

To check if the control plane (controller and registry) is up:

rl -sw "%{http_code}" "<Public IP of your cluster>:31200/health" -o /dev/null
rl -sw "%{http_code}" "<Public IP of your kubernetes>:31300/uptime" -o /dev/null

If both of them outputs 200, you can proceed to the next step.

Note: It can take around 1-2 minutes for the Pods to setup completely.

4. Create the Core Services

Finally, you can create the Core services and deployments of the app. (If you want to have social logins, please follow the steps here before deploying the core services)

bectl create -f core
lternatively
bectl create -f core/auth.yaml
bectl create -f core/<file-name>.yaml

bectl create -f core/webapp.yaml

To verify if the core services has finished setting up, you would need to check the logs of the Pod of the proxy. You can get the Pod name of the proxy using kubectl get pods

ctl logs proxy-***-**

You should look for the map, auth, mediator, player and room servers. Confirm if they are UP.

NING] 094/205214 (11) : Server room/room1 is UP, reason: Layer7 check passed ...
NING] 094/205445 (11) : Server auth/auth1 is UP, reason: Layer7 check passed ...
NING] 094/205531 (11) : Server map/map1 is UP, reason: Layer7 check passed ...
NING] 094/205531 (11) : Server mediator/mediator1 is UP, reason: Layer7 check passed ...
NING] 094/205531 (11) : Server player/player1 is UP, reason: Layer7 check passed ...

It can take around 5-10 minutes for these services to setup completely.

5. Explore your GameOn App

Now that you have successfully deployed your own app in the Bluemix Kubernetes Container Service, you can access it via its IP address and assigned Port.

https://169.xxx.xxx.xxx:30443/ You will need to use https on port 30443.

5.1 Add Social Logins

You may want to add social logins so you and your friends can explore the rooms together. To add social logins you would need to have developer accounts on the social app you want to use.

You will need to redeploy your Core services with the your own modified yaml files. The next step will show you where to add your API Keys.

Github

You can register your application in this link: New OAuth Application Github For the Homepage URL, you will need to put the IP address of your cluster and the port 30443.

https://169.xxx.xxx.xxx:30443/#/

For the Authorization callback URL, you will need to put the IP address and the port 30443 and point to the auth service of the app.

https://169.xxx.xxx.xxx:30443/auth/GitHubCallback

You can edit that in the GitHub later if you made a new cluster. Now, take note of the Client ID and Client Secret of the app. You will need to add this in the environment variables on the yaml files of your Core services


me: GITHUB_APP_ID
lue : '<yourGitHubClientId>'
me: GITHUB_APP_SECRET
lue : '<yourGitHubClientSecret>'

The application uses the keys(name) GITHUB_APP_ID and GITHUB_APP_SECRET and must exactly match this in yaml files.

Twitter

You can register your application with your Twitter account in this link: Create new app Twitter

For the name field, you can put the name you want for your app. For the Homepage URL, you will need to put the IP address of your cluster and the port 30443.

https://169.xxx.xxx.xxx:30443/#/

For the Authorization callback URL, you will need to put the IP address and the port 30443 and point to the auth service of the app.

https://169.xxx.xxx.xxx:30443/auth/TwitterAuth

Go to the Keys and Access Tokens section of the twitter application you just registered and take note of the Consumer Key and Consumer Secret of the app. You will need to add this in the environment variables on the yaml files of your Core services


me: TWITTER_CONSUMER_KEY
lue : '<yourGitHubClientId>'
me: TWITTER_CONSUMER_SECRET
lue : '<yourGitHubClientSecret>'

The application uses the keys(name) TWITTER_CONSUMER_KEY and TWITTER_CONSUMER_SECRET and must exactly match these in the core yaml files.

5.2 Add Rooms

You can build your own rooms by following this guide by the GameOn team. They have some sample rooms written in Java, Swift, Go, and more.

In this journey, you will deploy the sample room written in Java. You will deploy it in the same cluster as your GameOn App.

You can create these rooms by executing

bectl create -f sample-room

To register the deployed rooms in the cluster, you will need to use the UI of your app.

addroom

Troubleshooting

Privacy Notice

Sample Kubernetes Yaml file that includes this package may be configured to track deployments to IBM Cloud and other Kubernetes platforms. The following information is sent to a Deployment Tracker service on each deployment:

This data is collected from the Kubernetes Job in the sample application's yaml file. This data is used by IBM to track metrics around deployments of sample applications to IBM Cloud to measure the usefulness of our examples so that we can continuously improve the content we offer to you. Only deployments of sample applications that include code to ping the Deployment Tracker service will be tracked.

Disabling Deployment Tracking

Please comment out/remove the Metric Kubernetes Job portion at the end of the 'gameon-configmap.yaml' file.

References
License

Apache 2.0


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.