GithubHelp home page GithubHelp logo

nnathan / natganker Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 6 KB

KISS High Availability (HA) VPC NAT failover for AWS (deprecated, use: http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_NAT_Instance.html )

Shell 100.00%

natganker's Introduction

natganker

KISS NAT takeover for Amazon AWS

High-Level Overview

┌─────────────────────────────────────────────────────────┐
│                       Amazon VPC                        │
│     ┏━━━━━━━━━━┓                           ┌ ─ ─ ─ ─ ─  │
│     ┃ nat-gw-1 ┃─────ssh/ping heartbeat────  nat-gw-2 │ │
│     ┗━━━━━━━━━━┛                           └ ─ ─ ─ ─ ─  │
│           │                                             │
│           │                                             │
│           ├────────────────────────┐                    │
│           │                        │                    │
│           │                        │                    │
│           │                        │                    │
│ ┌─── rtr-table-a ──┐     ┌─── rtr-table-b ──┐           │
│ │ ┌~~~~~~~~~~~~~~┐ │     │ ┌~~~~~~~~~~~~~~┐ │           │
│ │ │   subnet 1   │ │     │ │   subnet 3   │ │           │
│ │ └~~~~~~~~~~~~~~┘ │     │ └~~~~~~~~~~~~~~┘ │           │
│ │ ┌~~~~~~~~~~~~~~┐ │     │ ┌~~~~~~~~~~~~~~┐ │           │
│ │ │   subnet 2   │ │     │ │   subnet 4   │ │           │
│ │ └~~~~~~~~~~~~~~┘ │     │ └~~~~~~~~~~~~~~┘ │           │
│ └──────────────────┘     └──────────────────┘           │
└─────────────────────────────────────────────────────────┘
                             │
                             │heartbeat failure
                             │
                             ▼
┌─────────────────────────────────────────────────────────┐
│                       Amazon VPC                        │
│     ┌ ─ ─ ─ ─ ─                            ┏━━━━━━━━━━┓ │
│       nat-gw-1 │─────ssh/ping heartbeat────┃ nat-gw-2 ┃ │
│     └ ─ ─ ─ ─ ─                            ┗━━━━━━━━━━┛ │
│                                                  │      │
│                                                  │      │
│           ┌────────────────────────┬─────────────┘      │
│           │                        │                    │
│           │                        │                    │
│           │                        │                    │
│ ┌─── rtr-table-a ──┐     ┌─── rtr-table-b ──┐           │
│ │ ┌~~~~~~~~~~~~~~┐ │     │ ┌~~~~~~~~~~~~~~┐ │           │
│ │ │   subnet 1   │ │     │ │   subnet 3   │ │           │
│ │ └~~~~~~~~~~~~~~┘ │     │ └~~~~~~~~~~~~~~┘ │           │
│ │ ┌~~~~~~~~~~~~~~┐ │     │ ┌~~~~~~~~~~~~~~┐ │           │
│ │ │   subnet 2   │ │     │ │   subnet 4   │ │           │
│ │ └~~~~~~~~~~~~~~┘ │     │ └~~~~~~~~~~~~~~┘ │           │
│ └──────────────────┘     └──────────────────┘           │
└─────────────────────────────────────────────────────────┘

Created with Monodraw

Requirements

  • Two NAT gateways:

    • Primary: actively forwards traffic and is associated with an elastic IP.
    • Secondary: runs natganker to passively monitor the primary instance and takeover if a healthcheck fails.
  • Both gateways must be able to perform healthchecks over the internal IP. This is easily solved by allowing ping or SSH to/from the internal subnet which both NAT gateways reside.

  • The primary NAT gateway instance should be the default route for routing tables in the region.

  • Both NAT instances requires the following IAM roles:

    • ec2:DescribeInstances
    • ec2:ModifyInstanceAttribute
    • ec2:DescribeAddresses
    • ec2:AssociateAddress
    • ec2:DisassociateAddress
    • ec2:DescribeSubnets
    • ec2:DescribeRouteTables
    • ec2:CreateRoute
    • ec2:ReplaceRoute

Usage

There are three ways to run natganker:

  1. Run on secondary NAT gateway and perform ping health check:

    • ./natganker.sh <primary-nat-instance-id> <primary-nat-elastic-ip>
  2. Run on secondary NAT gateway and perform SSH health check:

    • ./natganker.sh <primary-nat-instance-id> <primary-nat-elastic-ip> ssh
  3. Force failover to secondary NAT gateway:

    • ./natganker.sh <primary-nat-instance-id> <primary-nat-elastic-ip> forcefail

In (1) and (2) if a healthcheck fails, then the secondary NAT will replace itself as default route for all route tables defaulting to the primary NAT gateway. The script is idempotent so it can be rerun and will perform any necessary operations until the secondary NAT has the associated elastic IP and is the default route for all associated routing tables.

Using Monit

To ensure the script runs persistently you can use monit.

Here is an example configuration file which is placed in /etc/monit.d/natganker:

check process natganker matching bash.*natganker
   start program = "/root/natganker/natganker.sh <primary-nat-instance-id> <primary-nat-elastic-ip>" as uid "root" and gid "root"
   stop program = "/usr/bin/pkill -f bash.*natganker" as uid "root" and gid "root"

natganker's People

Contributors

nnathan avatar

Stargazers

Mark G. avatar

Watchers

 avatar James Cloos avatar  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.