Giter Site home page Giter Site logo

this-funk / openshiftexamples-autoscaling Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dudash/openshiftexamples-autoscaling

0.0 0.0 0.0 19.53 MB

:memo: Example showcasing how to use OpenShift to autoscale a webapp based on high-load

License: MIT License

openshiftexamples-autoscaling's Introduction

OpenShift Version OpenShift Version OpenShift Version

OpenShift Examples - Autoscaling

OpenShift can manually or automatically scale application pods up and down based on container metrics such as cpu and memory consumption. This git repo contains an intentionally simple example of automatically scaling (autoscaling) a webapp frontend with OpenShift.

Here's what it looks like:

Screenshot

ℹī¸ This example works in OpenShift Container Platform version 3.7+. It could work with other versions but has not been tested.

How to run this?

First off, you need access to an OpenShift cluster. Don't have an OpenShift cluster? That's OK, download the CDK for free here: https://developers.redhat.com/products/cdk/overview/. Second you have to have metrics enabled on your cluster.

There is a template for creating all the components of this example. Use the oc CLI tool:

oc new-project autoscaledemo

oc new-app -f https://raw.githubusercontent.com/dudash/openshiftexamples-autoscaling/master/autoscale_instant_template.yaml

If you don't like the CLI, another option is to create and project and import the template via the web console:

Create a new project, select Import YAML/JSON and then upload the raw file from this repo: autoscale_instant_template.yaml and make sure autoscaledemo is set as the Namespace parameter.

Now to showcase the autoscaling - let's simulate a large user load on the frontend webapp using Apache Benchmark. If you have ab installed just run it against the frontend URL. Or you can use OpenShfit to pull a container image containing ab and run it as self-terminating like this:

oc run web-load --rm --attach --image=jordi/ab -- -n 50000 -c 10 http://URL_GOES_HERE/

Why autoscale?

Two of the biggest reasons to leverage this capability in OpenShift:

  1. Provide better uptime for your apps when user demand spikes
  2. Reduce unecessary compute, scale down during periods of inactivity and up when needed

How does this work and how can I configure autoscaling?

In order the define autoscaling for an app, we first define how much cpu and memory an instance of the app should consume (both min and max). This becomes the guideline for OpenShift to know when to scale the pod up or down. These details are placed into what OpenShift calls a "deployment config" (you can read more about that here).

In this example if you want to tweak a few things to in the example the following are the most common asks:

Change the min/max number of replicated containers of the web frontend and the CPU request target:

oc autoscale dc/webapp --min 1 --max 5 --cpu-percent=60

Change the request and limit values for the web frontend deployment:

oc set resources dc/webapp --requests=cpu=200m,memory=256Mi --limits=cpu=400m,memory=512Mi

You can read more about the details of compute resource request and limits here. You can read about how Quality of Service (QoS) can be leveraged here. And read about how to further configure autoscaling here.

About the code / software architecture

The parts in action here are:

  • Simple web front end to collect user input and push to a database or backend API layer
  • Backend service, a MongoDB database
  • Instant app template YAML file (to create/configure everything easily)
  • Key platform components that enable this example
    • container building (source to image)
    • container CPU / memory monitoring
    • container replication and service layer
    • software defined networking and routing layer

License

Under the terms of the MIT.

openshiftexamples-autoscaling's People

Contributors

dudash avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.