Aaron Schlesinger
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    2
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Multi-tenant KEDA HTTP Addon design _June 22, 2021_ _[@arschles](https://github.com/arschles)_ **This document is a work in progess.** This document is an extension of [issue #183](https://github.com/kedacore/http-add-on/issues/183) in the KEDA HTTP Addon repository. In this issue, [@yaron2](https://github.com/yaron2) requested that the interceptor and external scaler become multi-tenant, so that many `Deployment`s could be controlled by a single scaler and routed by a single interceptor (or many replicas of the same interceptor `Deployment`). ## Current design Currently, when a new `HTTPScaledObject` is created, the HTTP Addon operator creates a new external scaler and interceptor. As implied above, there is currently a 1:1 mapping from interceptor/scaler to application, which is defined as a `Deployment` & `Service`. The interceptor watches the `Deployment` and routes to the `Service`. The scaler requests the size of the pending HTTP request queue on each interceptor by the following process: 1. request the IP address of each interceptor pod from the Kubernetes control plane API 2. make a request to each interceptor to get the size of the pending HTTP request queue 3. calculate the sum of all the queues 4. report the sum to KEDA Both the interceptor and scaler are configured to interact with the app `Service`/`Deployment` by environment variables. These variables are set by the operator. ## Proposed design changes Since both of these components are going to become multi-tenant, the operator should not create them when a new `HTTPScaledObject` is created. Instead, both the interceptor and external scaler should be made aware of a new application `Service`/`Deployment` by the creation of a new `HTTPScaledObject`. ### Scaler changes Similar to current functionality, the scaler must still report metrics to KEDA. Instead of currently reporting a single metric -- the sum of pending HTTP queue sizes across all interceptors -- it must report one metric per application (in the same namespace as it runs). For example, if there are 7 applications in the same namespace, the scaler needs to report 7 metrics to KEDA. This change has implications for the interceptor, which are outlined below. ### Interceptor Changes The interceptor has two major changes. First, it needs to report more granular pending queue sizes to the scaler -- pending queue sizes per application. Second, it needs to be able to route requests dynamically based on the properties of a single request. #### Interceptor routing table When it receives an incoming request, the interceptor must look at the hostname (i.e. the `Host` header) and decide to which `Service` to forward the request. This new functionality implies a lookup table, which we'll call a routing table. The routing table is a simple key/value storage system that maps from `Host` header to backing `Service`. The interceptor will only route to `Service`s in the same Kubernetes namespace. This routing table should be stored in a central location -- likely the set of `HTTPScaledObject`s in the same namespace -- and cached in memory of each interceptor process. #### Granular metrics The scaler requires that the interceptor report pending queue sizes per application, rather than total pending queue size. Since the interceptor will have a routing table and will dynamically route requests, it will also keep count of the pending queue size _per `HTTPScaledObject`_ -- using the routing table -- rather than globally. Once the interceptor is changed to keep one counter per application, it that information will be added into the scaler -> interceptor RPC call, rather than just the single global number. ### Operator changes The operator's major functionality is currently to create and configure a new scaler and interceptor for a new `HTTPScaledObject`. This design calls for multi-tenant scalers and interceptors, so that behavior will be removed. Instead, the operator will be responsible for storing and updating the routing table and notifying the interceptors about changes to the routing table. #### Changes to the `HTTPScaledObject` `HTTPScaledObject`s have half the information needed for the routing table. They have the `Service`/`Deployment` to forward to, but not the `Host` information. That information will need to be added to the `spec` section of `HTTPScaledObject`s. #### Assembling the routing table When a new `HTTPScaledObject` is created, modified, or removed, the operator is currently notified and a reconcile loop is initialized (indeed, a `Reconcile` function is called). When any change happens to the set of `HTTPScaledObject`s in a namespace, the operator will calculate and store the routing table. Storage will be (eventually) be pluggable such that the cluster operator can choose where to store the table. By default, it will be stored in a `ConfigMap` in the same namespace. #### Updating the routing table On each update to the routing table, the operator will serialize the routing table into a `ConfigMap` with a well-known name. Interceptors will watch Kubernetes events on the same `ConfigMap` and, on every updated or added event, will deserialize the data therein and save the new routing table to their in-memory copy. Interceptors will also fetch a complete copy of the `ConfigMap` every `$DURATION`, deserialize the contents, and save the new routing table to their in-memory copy. This functionality ensures that, if the watch stream is broken or there are other network issues, any given interceptor will either converge to the latest routing table or fail after no more than `$DURATION`. #### Verifying that the routing table is updated >This section is a work in progress. It is tracked in https://github.com/kedacore/http-add-on/issues/225, and the contents of this section may be out of date. After an `HTTPScaledObject` is created, deleted or updated, it would be helpful for cluster operators to verify that the change has been propagated across the fleet of interceptors. The operator will convey this information in the `status` field of any given `HTTPScaledObject`. That functionality will ensure that a cluster operator can verify that a specific application is up to date. >When an `HTTPScaledObject` is deleted, the operator won't have a `status` field to update. In the case that an interceptor does not update its routing table, it will, at worst, route to the backing application for a short time after an `HTTPScaledObject` is deleted until it updates its routing table. After the operator gets an update to the set of `HTTPScaledObject`s (i.e. a new one, or a change to an existing one), and it issues the "ping update" request, it can determine when all interceptors finished their update by comparing the unique IDs (i.e. the [hostname](https://kubernetes.io/docs/concepts/containers/container-environment/#container-information)) of each pod in the `Deployment` to the unique IDs to those that have made the fetch-routing-table RPC. The pseudocode for this process is as follows: ``` pods = interceptor_deployment.get_pods() unique_id = uuid.new() for pod in pods: pod.send_ping_update_request(unique_id) respondent_pods = accept_ping_update_requests() TODO ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully