Skip to content

A very basic shopping cart application to show Stateful Canary Deployments on Kubernetes using Spring Boot and Infinispan

License

Notifications You must be signed in to change notification settings

redhat-developer-demos/popular-movie-store

Repository files navigation

Popular Movie Store

Overview

A simple Spring Boot based shopping cart application that will demonstrate,

Setup Local Kubernetes Cluster

The kubernetes cluster can be set locally using

(OR)

Adding role to Service Account

infinispan-cloud uses KUBE_PING to query the Kube API for nodes, pods and labels we need to add permissions, hence the service account associated with the deployment need to be added with the required roles to allow infinispan to query kubernetes API.

This application uses a service account called popular-movie-store to run the pod, the service account popular-movie-store should be given view permissions to use Kube API.

Typically we do the following on OpenShift to add the role to the user,

oc policy add-role-to-user view system:serviceaccount:$(oc project -q):default -n $(oc project -q)  # (1)

oc policy add-role-to-user view system:serviceaccount:$(oc project -q):popular-movie-store -n $(oc project -q) # (2)
  1. Adds view role to default service account

  2. Adds view role to popular-movie-store service account

Since we use fabric8 maven plugin we have automated this step, using the rb.yml resource

API Key

You need the themoviedb API key for running the application, you can get one from themoviedb.

Once you have the API key from themoviedb, generate a base64 encoded value of it,

echo -n '<your-api-key>' | openssl base64

Deploying

Assuming you having a running Kubernetes cluster, execute the following command to deploy the application,

./mvnw  -DapiKey=<api-key> clean fabric8:deploy #(1)

./mvnw -Pcanary clean -DapiKey=<api-key> clean fabric8:deploy #(2)
  1. The fabric8:deploy will trigger deployment of manifests in Kubernetes cluster

  2. The application is configured with maven profile called canary pom.xml, which aids in performing the Canary Releases

Tip

Everytime you do fabric8:deploy all resources are recreated this could be an issue with services as nodePort will refreshed on every deployment, to avoid that just add -Dfabric8.deploy.ignoreServices when doing re-deployments.

Note
The build will take some time for the very first deployment, as bunch of images needs to be pulled.

Accessing the Application

Once the application is deployed in Kubernetes you can access the application with one of the following ways

If you are using minikube you can open the application in the browser using the command minikube service popular-movie-store

(OR)

If you are using minishift you can OpenShift console in the browser using the command minishift console and find the application url from the console refer to screenshot below

Movie Store Service URL

Sessions API

The core idea of the demo is to see if my sessions stand with rolling upgrade of the applications, to know your current sessions you can access the url http://<application-url>/sessions, which will return the JSON of the currently active sessions, where the application url is the same one from Accessing the Application

Undeploying

The application can be undeployed using the following fabric8-maven-plugin goals,

Normal release

./mvnw  -DapiKey=<api-key> fabric8:undeploy

Canary Release

./mvnw -Pcanary -DapiKey=<api-key> fabric8:undeploy

Pipelines

The application is enabled for OpenShit CI/CD via Jenkins. Fork your the project to your user id and then,

  • Login to the OpenShift server using oc login, please make sure you login with user who can has cluster admin role to enable creation of github secrets

  • From the Project root do mvn fabric8:import

  • You will now see the Buid Config for the project created in Github

  • To get the GitHub webhook url run the command oc describe bc/popular-moive-store

  • Add the GitHub WebHook url displayed in GitHub Web Hook settings

You are now all set to trigger the pipelines via GitHub pushes.

Note
Automatic builds for GitHub will work only if the project is reachable via internet otherwise you need to start the builds manually

Utilities and Tools

Applications

The following applications are very handy for development, and its purely optional to have them installed to the kubernetes environment, they are available at Kubernetes or OpenShift for respective environments

  • exposecontroller - a utility that can exposes the service automatically when it the manifests has label expose:true

  • configmapcontroller - a utility that does a rebounce of the pod when the configmap mentioned in the annotation of the deployment changes

Disclaimer

This demo application uses MovieDB API for getting some movie posters. All data displayed in the demo is only used for demonstrates various features of the demo and teaching.

License

Copyright 2017 Red Hat

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.

About

A very basic shopping cart application to show Stateful Canary Deployments on Kubernetes using Spring Boot and Infinispan

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published