Skip to content

Commit 430d395

Browse files
committed
Add support for Azure VMSS
1 parent 1575648 commit 430d395

File tree

361 files changed

+181887
-37149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

361 files changed

+181887
-37149
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A clear and concise description of what the bug is.
1212
Provide the following files as part of the bug report
1313

1414
* NGINX Plus configuration. Run `sudo nginx -T` to gather the full configuration
15-
* nginx-asg-sync configuration from `/etc/nginx/aws.yaml`
15+
* nginx-asg-sync configuration from `/etc/nginx/config.yaml`
1616

1717
Steps to reproduce the behavior, such as:
1818
1. Scale from 2 to 5 EC2 instances

Gopkg.lock

Lines changed: 80 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@
4040
[[constraint]]
4141
name = "github.com/nginxinc/nginx-plus-go-client"
4242
version = "0.4.0"
43+
44+
# https://github.com/Azure/go-autorest/issues/439#issuecomment-521732075
45+
[[override]]
46+
name = "github.com/Azure/go-autorest"
47+
version = "13.0.0"

README.md

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
[![Build Status](https://travis-ci.org/nginxinc/nginx-asg-sync.svg?branch=master)](https://travis-ci.org/nginxinc/nginx-asg-sync) [![FOSSA Status](https://app.fossa.io/api/projects/custom%2B1062%2Fgithub.com%2Fnginxinc%2Fnginx-asg-sync.svg?type=shield)](https://app.fossa.io/projects/custom%2B1062%2Fgithub.com%2Fnginxinc%2Fnginx-asg-sync?ref=badge_shield) [![Go Report Card](https://goreportcard.com/badge/github.com/nginxinc/nginx-asg-sync)](https://goreportcard.com/report/github.com/nginxinc/nginx-asg-sync)
22

3-
# NGINX Plus Integration with AWS Auto Scaling groups -- nginx-asg-sync
3+
# NGINX Plus Integration with Cloud Autoscaling -- nginx-asg-sync
44

5-
**nginx-asg-sync** allows [NGINX Plus](https://www.nginx.com/products/) to discover instances of [AWS Auto Scaling groups](http://docs.aws.amazon.com/autoscaling/latest/userguide/WhatIsAutoScaling.html). When the number of instances in an Auto Scaling group changes, nginx-asg-sync adds the new instances to the NGINX Plus configuration and removes the terminated ones.
5+
**nginx-asg-sync** allows [NGINX Plus](https://www.nginx.com/products/) to discover instances (virtual machines) of a scaling group of a cloud provider. The following providers are supported:
6+
7+
* AWS [Auto Scaling groups](http://docs.aws.amazon.com/autoscaling/latest/userguide/WhatIsAutoScaling.html)
8+
* Azure [Virtual Machine Scale Sets](https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/)
9+
10+
When the number of instances changes, nginx-asg-sync adds the new instances to the NGINX Plus configuration and removes the terminated ones.
611

712
## How It Works
8-
nginx-asg-sync is an agent process that runs on the same EC2 instance as NGINX Plus. It polls for changes to the backend Auto Scaling groups via the AWS Auto Scaling API.
13+
nginx-asg-sync is an agent process that runs on the same instance as NGINX Plus. It polls for changes to the backend instance groups via the Cloud Provider API.
14+
915
When it sees that a scaling event has happened, it adds or removes the corresponding backend instances from the NGINX Plus configuration via the NGINX Plus API.
1016

11-
**Note:** nginx-asg-sync does not scale Auto Scaling groups, it only gets the IP addresses of the instances of Auto Scaling groups.
17+
**Note:** nginx-asg-sync does not scale cloud scaling groups, it only gets the IP addresses of the instances in the groups.
1218

13-
In the example below, NGINX Plus is configured to load balance among the instances of two Auto Scaling groups -- Backend One and Backend Two.
19+
In the example below (AWS), NGINX Plus is configured to load balance among the instances of two AWS Auto Scaling groups -- Backend One and Backend Two.
1420
nginx-asg-sync, running on the same instance as NGINX Plus, ensures that whenever you scale the Auto Scaling groups, the corresponding instances are added (or removed) from the NGINX Plus configuration.
1521

1622
![nginx-asg-sync-architecture](https://cdn-1.wp.nginx.com/wp-content/uploads/2017/03/aws-auto-scaling-group-asg-sync.png)
@@ -21,15 +27,13 @@ Below you will find documentation on how to use nginx-asg-sync.
2127
**Note:** the documentation for **the latest stable release** is available via a link in the description of the release. See the [releases page](https://github.com/nginxinc/nginx-asg-sync/releases).
2228

2329
**Contents:**
24-
- [NGINX Plus Integration with AWS Auto Scaling groups -- nginx-asg-sync](#nginx-plus-integration-with-aws-auto-scaling-groups----nginx-asg-sync)
30+
- [NGINX Plus Integration with Cloud Autoscaling -- nginx-asg-sync](#nginx-plus-integration-with-cloud-autoscaling----nginx-asg-sync)
2531
- [How It Works](#how-it-works)
2632
- [Documentation](#documentation)
2733
- [Supported Operating Systems](#supported-operating-systems)
28-
- [Setting up Access to the AWS API](#setting-up-access-to-the-aws-api)
2934
- [Installation](#installation)
30-
- [Configuration](#configuration)
3135
- [NGINX Plus Configuration](#nginx-plus-configuration)
32-
- [nginx-asg-sync Configuration](#nginx-asg-sync-configuration)
36+
- [Configuration for Cloud Providers](#configuration-for-cloud-providers)
3337
- [Usage](#usage)
3438
- [Troubleshooting](#troubleshooting)
3539
- [Building a Software Package](#building-a-software-package)
@@ -45,13 +49,6 @@ We provide packages for the following operating systems:
4549

4650
Support for other operating systems can be added.
4751

48-
## Setting up Access to the AWS API
49-
50-
nginx-asg-sync uses the AWS API to get the list of IP addresses of the instances of an Auto Scaling group. To access the AWS API, nginx-asg-sync must have credentials. To provide credentials to nginx-asg-sync:
51-
52-
1. [Create an IAM role](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html) and attach the predefined `AmazonEC2ReadOnlyAccess` policy to it. This policy allows read-only access to EC2 APIs.
53-
1. When you launch the NGINX Plus instance, add this IAM role to the instance.
54-
5552
## Installation
5653

5754
1. Get a software package for your OS:
@@ -61,17 +58,15 @@ nginx-asg-sync uses the AWS API to get the list of IP addresses of the instances
6158
* For Amazon Linux or CentOS/RHEL, run: `$ sudo rpm -i <package-name>.rpm`
6259
* For Ubuntu, run: `$ sudo dpkg -i <package-name>.deb`
6360

64-
## Configuration
61+
### NGINX Plus Configuration
6562

66-
As an example, we configure NGINX Plus to load balance two AWS Auto Scaling groups -- backend-group-one and backend-group-two. NGINX Plus routes requests to the appropriate Auto Scaling group based on the request URI:
63+
As an example, we configure NGINX Plus to load balance two groups of instances -- backend-group-one and backend-group-two. NGINX Plus routes requests to the appropriate group based on the request URI:
6764

6865
* Requests for /backend-one go to Backend One group.
6966
* Requests for /backend-two go to Backend Two group.
7067

7168
This example corresponds to [the diagram](#how-it-works) at the top of this README.
7269

73-
### NGINX Plus Configuration
74-
7570
```nginx
7671
upstream backend-one {
7772
zone backend-one 64k;
@@ -93,10 +88,30 @@ server {
9388
proxy_pass http://backend-one;
9489
}
9590
91+
location @hc-backend-one {
92+
internal;
93+
proxy_connect_timeout 1s;
94+
proxy_read_timeout 1s;
95+
proxy_send_timeout 1s;
96+
97+
proxy_pass http://backend-one;
98+
health_check interval=1s mandatory;
99+
}
100+
96101
location /backend-two {
97102
proxy_set_header Host $host;
98103
proxy_pass http://backend-two;
99104
}
105+
106+
location @hc-backend-two {
107+
internal;
108+
proxy_connect_timeout 1s;
109+
proxy_read_timeout 1s;
110+
proxy_send_timeout 1s;
111+
112+
proxy_pass http://backend-two;
113+
health_check interval=1s mandatory;
114+
}
100115
}
101116
102117
server {
@@ -112,40 +127,18 @@ server {
112127
}
113128
```
114129

115-
* We declare two upstream groups – **backend-one** and **backend-two**, which correspond to our Auto Scaling groups. However, we do not add any servers to the upstream groups, because the servers will be added by nginx-aws-sync. The `state` directive names the file where the dynamically configurable list of servers is stored, enabling it to persist across restarts of NGINX Plus.
130+
* We declare two upstream groups – **backend-one** and **backend-two**, which correspond to our instance groups. However, we do not add any servers to the upstream groups, because the servers will be added by nginx-aws-sync. The `state` directive names the file where the dynamically configurable list of servers is stored, enabling it to persist across restarts of NGINX Plus.
116131
* We define a virtual server that listens on port 80. NGINX Plus passes requests for **/backend-one** to the instances of the Backend One group, and requests for **/backend-two** to the instances of the Backend Two group.
117132
* We define a second virtual server listening on port 8080 and configure the NGINX Plus API on it, which is required by nginx-asg-sync:
118133
* The API is available at **127.0.0.1:8080/api**
119134

120-
### nginx-asg-sync Configuration
121-
122-
nginx-asg-sync is configured in **/etc/nginx/aws.yaml**. For our example, we define the following configuration:
123-
124-
```yaml
125-
region: us-west-2
126-
api_endpoint: http://127.0.0.1:8080/api
127-
sync_interval_in_seconds: 5
128-
cloud_provider: AWS
129-
upstreams:
130-
- name: backend-one
131-
autoscaling_group: backend-one-group
132-
port: 80
133-
kind: http
134-
- name: backend-two
135-
autoscaling_group: backend-two-group
136-
port: 80
137-
kind: http
138-
```
135+
Because cloud provider APIs return the instances IP addresses before the instances are ready and/or provisioned, we recommend setting up mandatory active [healthchecks](http://nginx.org/en/docs/http/ngx_http_upstream_hc_module.html#health_check) for all upstream groups - **@hc-backend-one** and **@hc-backend-two**. This way, NGINX Plus won't pass any request to an instance that is still being provisioned or has been deleted recently.
136+
137+
Small timeouts ensure that a health check will fail fast if the backend instance is not healthy. Also, the mandatory parameter ensures NGINX Plus won't consider a newly added instance healthy until a health check passes.
138+
139+
### Configuration for Cloud Providers
139140

140-
* The `region` key defines the AWS region where we deploy NGINX Plus and the Auto Scaling groups.
141-
* The `api_endpoint` key defines the NGINX Plus API endpoint.
142-
* The `sync_interval_in_seconds` key defines the synchronization interval: nginx-asg-sync checks for scaling updates every 5 seconds.
143-
* The `cloud_provider` key defines a cloud provider that will be used. The default is `AWS`. This means the key can be empty if using AWS.
144-
* The `upstreams` key defines the list of upstream groups. For each upstream group we specify:
145-
* `name` – The name we specified for the upstream block in the NGINX Plus configuration.
146-
* `autoscaling_group` – The name of the corresponding Auto Scaling group.
147-
* `port` – The port on which our backend applications are exposed.
148-
* `kind` – The protocol of the traffic NGINX Plus load balances to the backend application, here `http`. If the application uses TCP/UDP, specify `stream` instead.
141+
See the example for your cloud provider: [AWS](examples/aws.md), [Azure](examples/azure.md).
149142

150143
## Usage
151144

build/package/debian/aws.yaml.example

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# example configuration for AWS
2+
3+
# cloud_provider: AWS
4+
# region: us-west-2
5+
# api_endpoint: http://127.0.0.1:8080/api
6+
# sync_interval_in_seconds: 5
7+
# upstreams:
8+
# - name: backend1
9+
# autoscaling_group: backend-group-1
10+
# port: 80
11+
# kind: http
12+
# - name: backend2
13+
# autoscaling_group: backend-group-2
14+
# port: 80
15+
# kind: http
16+
# - name: tcp-backend
17+
# autoscaling_group: backend-group-3
18+
# port: 80
19+
# kind: stream
20+
21+
# example configuration for Azure
22+
23+
# cloud_provider: Azure
24+
# subscription_id: my_subscription_id
25+
# resource_group: my_resource_group
26+
# api_endpoint: http://127.0.0.1:8080/api
27+
# sync_interval_in_seconds: 5
28+
# upstreams:
29+
# - name: backend1
30+
# virtual_machine_scale_set: backend-group-1
31+
# port: 80
32+
# kind: http
33+
# - name: backend2
34+
# virtual_machine_scale_set: backend-group-2
35+
# port: 80
36+
# kind: http
37+
# - name: tcp-backend
38+
# virtual_machine_scale_set: backend-group-3
39+
# port: 80
40+
# kind: stream

build/package/debian/control

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ Homepage: https://github.com/nginxinc/nginx-asg-sync
99
Package: nginx-asg-sync
1010
Architecture: any
1111
Depends: ${shlibs:Depends}, ${misc:Depends}
12-
Description: NGINX Plus integration with AWS Auto Scaling Groups
12+
Description: NGINX Plus Integration with Cloud Autoscaling
1313
This package contains software that integrates NGINX Plus
14-
with AWS Auto Scaling groups
14+
with AWS Auto Scaling groups and Azure Virtual Machine Scale Sets

0 commit comments

Comments
 (0)