This project 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. GameOn! users start by creating a simple room, the building block of any adventure game. A user can create in text a simple room in any one of various languages in just a few minutes.
There are several microservices used in this app
- Proxy: HAProxy based, and is responsible for surfacing the collection of APIs as a single facade for the entire application.
- WebApp: Webapp is a simple nginx process that serves the static files that comprise the front-end of the UI.
- Player: Players, are represented by the player Java microservice service, which provides a public API for CRUD operations, and for managing API tokens.
- Auth: Java microservice to allow players to connect and identify themselves via a selected "social login"
- Mediator**: The Mediator service is implemented in Java using WebSphere Liberty, and connects players to rooms over Websockets
- Map: The Map service is a Java EE application running on WebSphere Liberty that provides a public REST API using JAX-RS. It stores data in a NoSQL data store, either couchdb or Cloudant
- Room: Java based room implementation
- Amalgam8: Amalgam8 supplies Registry, and a Controller, via which it implements the Service Discovery, and Service Proxying
- Kafka: Publish/Subscribe solution used by Amalgam8
Everything would be hosted on a Kubernetes Cluster where you can access your own GameOn app from anywhere.
Create a Kubernetes cluster with either Minikube for local testing, 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.
If you want to deploy GameOn! directly to Bluemix, click on 'Deploy to Bluemix' button below to create a Bluemix DevOps service toolchain and pipeline for deploying the sample, else jump to Steps
You will need to create your Kubernetes cluster first and make sure it is fully deployed in your Bluemix account.
Please follow the Toolchain instructions to complete your toolchain and pipeline.
- Modify the Core services yaml files
- Create volumes in your Cluster
- Create the Platform Services
- Create the Core Services
- Explore your GameOn App
- 5.1 Add Social Logins
- 5.2 Add Rooms
First, you'll need to update the yaml files for the core services and setup.yaml. You will need to get the Public IP address of your cluster.
$ kubectl get nodes NAME STATUS AGE 169.xx.xxx.xxx Ready 13d
Take note of the IP address. Go to the core folder and change the following values on the environment variables of the container on every file to the IP address you have. Maintain the port number.
Example: ... value : https://169.47.241.yyy:30443/players/v1/accounts TO -> value : https://169.xx.xxx.xxx:30443/players/v1/accounts ...
You can also use the script provided that replaces the default values to the IP of your current cluster.
./replace_ip_linux.sh
for linux./replace_ip_OSX.sh
for macOS
Core yaml files should look like this. Change the following env variables spec: containers: - image: gameontext/gameon-* name: * env: ... - name: FRONT_END_PLAYER_URL value : https://169.47.241.137:30443/players/v1/accounts - name: FRONT_END_SUCCESS_CALLBACK value : https://169.47.241.137:30443/#/login/callback - name: FRONT_END_FAIL_CALLBACK value : https://169.47.241.137:30443/#/game - name: FRONT_END_AUTH_URL value : https://169.47.241.137:30443/auth ... - name: PROXY_DOCKER_HOST value : '169.47.241.137' ...
setup.yaml ... spec: restartPolicy: Never containers: - name: setup image: anthonyamanse/keystore env: - name: IP value: 169.47.241.137 ...
You would need to create a volume for your cluster. You can use the provided yaml file. The volume will also be used by the core services. This would contain some required keystores and server configurations.
$ kubectl create -f local-volumes.yaml persistent volumes "local-volume-1" created persistent 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. Once it is done, the Pod will terminate. You may delete the pod after.
$ kubectl create -f setup.yaml
If you want to confirm that the Pod has successfully imported the keystores, you can view the Pod's logs.
$ kubectl logs setup Checking for keytool... Checking for openssl... Generating key stores using <Public-IP-of-your-cluster>:30443 Certificate stored in file <keystore/gameonca.crt> Certificate was added to keystore Certificate reply was installed in keystore Certificate stored in file <keystore/app.pem> MAC verified OK Certificate was added to keystore Entry for alias <*> successfully imported. ... Entry for alias <**> successfully imported. Import command completed: 104 entries successfully imported, 0 entries failed or cancelled
You can now create the Platform services and deployments of the app.
$ kubectl create -f platform OR alternatively $ kubectl create -f platform/controller.yaml $ kubectl create -f platform/<file-name>.yaml ... $ kubectl create -f platform/registry.yaml
To check if the control plane (controller and registry) is up:
$ curl -w "%{http_code}" "<Public IP of your cluster>:31200/health" -o /dev/null $ curl -w "%{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.
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)
$ kubectl create -f core OR alternatively $ kubectl create -f core/auth.yaml $ kubectl create -f core/<file-name>.yaml ... $ kubectl 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
kubectl logs proxy-***-**
You should look for the map, auth, mediator, player and room servers. Confirm if they are UP.
[WARNING] 094/205214 (11) : Server room/room1 is UP, reason: Layer7 check passed ... [WARNING] 094/205445 (11) : Server auth/auth1 is UP, reason: Layer7 check passed ... [WARNING] 094/205531 (11) : Server map/map1 is UP, reason: Layer7 check passed ... [WARNING] 094/205531 (11) : Server mediator/mediator1 is UP, reason: Layer7 check passed ... [WARNING] 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.
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.
- You will see the homepage of your app on that address.
- Click on Enter to log in as Anonymous User(You will need to setup your own Social Login API keys if you want to use your accounts on Github,Twitter,etc..)
- The app will prompt you to enter your desired Username and Favorite Color
- Congratulations! You now have your own GameOn app running on Bluemix! You may now wish to explore on creating new rooms and adding 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.
You can register your application in this link: New OAuth Application For the Homepage URL, you will need to put the IP address of your cluster and the port 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.
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
... - name: GITHUB_APP_ID value : '<yourGitHubClientId>' - name: GITHUB_APP_SECRET value : '<yourGitHubClientSecret>' ...
The application uses the keys(name) GITHUB_APP_ID and GITHUB_APP_SECRET and must exactly match this in yaml files.
You can register your application with your Twitter account in this link: Create new app
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.
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.
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
... - name: TWITTER_CONSUMER_KEY value : '<yourGitHubClientId>' - name: TWITTER_CONSUMER_SECRET value : '<yourGitHubClientSecret>' ...
The application uses the keys(name) TWITTER_CONSUMER_KEY and TWITTER_CONSUMER_SECRET and must exactly match these in the core yaml files.
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 rooms written in Java and Swift. You will deploy it in the same cluster as your GameOn App.
You can create these rooms by executing
$ kubectl create -f sample-rooms
To register the deployed rooms in the cluster, you will need to use the UI of your app.
-
Enter the necessary information of the room. (Leave the Github Repo and Health Endpoint fields blank.) Then click
Register
Note: In the samples, the Java Room uses port 9080, while the Swift room uses port 8080.
- You now have successfully registered your rooms in your Map. You can go to them directly by typing these commands in the UI:
/listmyrooms
and use the id in/teleport <id-of-the-room>
You can learn more about the details of registering a room here.
- GameOn - The original game on app. The journey is based on deploying GameOn using Dockers