All Projects → martensson → Nixy

martensson / Nixy

Licence: mit
nixy - nginx auto configuration and service discovery for Mesos/Marathon

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Nixy

Marathon Lb
Marathon-lb is a service discovery & load balancing tool for DC/OS
Stars: ✭ 449 (+73.36%)
Mutual labels:  marathon, load-balancer, mesos
Traefik
The Cloud Native Application Proxy
Stars: ✭ 36,089 (+13833.98%)
Mutual labels:  marathon, load-balancer, mesos
Panteras
PanteraS - PaaS - Platform as a Service in a box
Stars: ✭ 189 (-27.03%)
Mutual labels:  marathon, mesos
Dcos
DC/OS - The Datacenter Operating System
Stars: ✭ 2,316 (+794.21%)
Mutual labels:  marathon, mesos
micro-service-practice
OpenStack+Docker+RestAPI+OAuth/HMAC+RabbitMQ/ZMQ+OpenResty/HAProxy/Nginx/APIGateway+Bootstrap/AngularJS+Ansible+K8S/Mesos/Marathon构建/探索微服务最佳实践。
Stars: ✭ 25 (-90.35%)
Mutual labels:  marathon, mesos
My Cheat Sheets
A place to keep all my cheat sheets for the complete development of ASIC/FPGA hardware or a software app/service.
Stars: ✭ 94 (-63.71%)
Mutual labels:  marathon, mesos
Paasta
An open, distributed platform as a service
Stars: ✭ 1,569 (+505.79%)
Mutual labels:  marathon, mesos
marathon-appcop
Marathon applications law enforcement
Stars: ✭ 18 (-93.05%)
Mutual labels:  marathon, mesos
Linkerdcosdockerfile
Linker Dcos DockerFile&DockerCompose yml file
Stars: ✭ 8 (-96.91%)
Mutual labels:  marathon, mesos
resty-marathon-lb
基于 OpenResty 的 Marathon 服务发现 & 路由
Stars: ✭ 13 (-94.98%)
Mutual labels:  marathon, mesos
spring-cloud-marathon
Spring Cloud integration with Mesos and Marathon
Stars: ✭ 29 (-88.8%)
Mutual labels:  marathon, mesos
dcos-autoscaler
Autoscaler for DC/OS hosted in a cloud provider
Stars: ✭ 12 (-95.37%)
Mutual labels:  marathon, mesos
Docker Cloud Platform
使用Docker构建云平台,Docker云平台系列共三讲,Docker基础、Docker进阶、基于Docker的云平台方案。OpenStack+Docker+RestAPI+OAuth/HMAC+RabbitMQ/ZMQ+OpenResty/HAProxy/Nginx/APIGateway+Bootstrap/AngularJS+Ansible+K8S/Mesos/Marathon构建/探索微服务最佳实践。
Stars: ✭ 86 (-66.8%)
Mutual labels:  marathon, nginx
Waiter
Runs, manages, and autoscales web services on Mesos and Kubernetes
Stars: ✭ 65 (-74.9%)
Mutual labels:  marathon, mesos
Marathon Consul
Integrates Marathon apps with Consul service discovery.
Stars: ✭ 174 (-32.82%)
Mutual labels:  marathon, mesos
xxcloud
xxcloud,旨在整合数据中心异构虚拟化资源为统一的资源池,并在资源池上为用户提供各类IAAS、PAAS服务。
Stars: ✭ 64 (-75.29%)
Mutual labels:  marathon, mesos
Swan
A Distributed, Highly Available Mesos Scheduler, Inspired by the design of Google Borg
Stars: ✭ 411 (+58.69%)
Mutual labels:  marathon, mesos
sbt-marathon
An sbt plugin for launching application containers on the Mesosphere Marathon platform.
Stars: ✭ 23 (-91.12%)
Mutual labels:  marathon, mesos
marathon-slack
Integration for Marathon's Event Bus with Slack
Stars: ✭ 42 (-83.78%)
Mutual labels:  marathon, mesos
consul-registration-hook
Hook that can be used for synchronous registration and deregistration in Consul discovery service on Kubernetes or Mesos cluster with Allegro executor
Stars: ✭ 17 (-93.44%)
Mutual labels:  marathon, mesos

nixy release Build Status Go Report Card license

nginx gopher

Nixy is a daemon that automatically configures Nginx for web services deployed on Apache Mesos and Marathon.

Features:

  • Reverse proxy and load balancer for your microservices running inside Mesos and Marathon
  • Single binary with no other dependencies (except Nginx/Openresty)
  • Written in Go to be blazingly fast and concurrent.
  • All the features you would expect from Nginx:
    • HTTP/TCP/UDP load balancing, HTTP/2 termination, websockets, SSL/TLS termination, caching/compression, authentication, media streaming, static file serving, etc.
  • Zero downtime with Nginx fall-back mechanism for sick backends and hot config reload.
  • Easy to customize your needs with templating.
  • Statistics via statsd (successful/failed updates, timings).
  • Real-time updates via Marathon's event stream (Marathon v0.9.0), so no need for callbacks.
  • Support for Marathon HA cluster, auto detects sick endpoints.
  • Automatic service discovery of all running tasks inside Mesos/Marathon, including their health status.
  • Basic auth support.
  • Health checks for errors in template, nginx config or Marathon endpoints.
  • Built-in Prometheus exporter for metrics and alerts.
  • ....

Compatibility

  • All versions of Marathon >= v0.9.0
  • All versions of Nginx or OpenResty (Also possible to run inside Docker).

Getting started

  1. Install nixy from pre-compiled packages. Check releases page.

  2. Edit config (default on ubuntu is /etc/nixy.toml):

    # Nixy listening port
    port = "6000"
    # X-Proxy header, defaults to hostname
    xproxy = ""
    
    # Marathon API
    marathon = ["http://example01:8080", "http://example02:8080"] # add all HA cluster nodes in priority order.
    user = "" # leave empty if no auth is required.
    pass = ""
    # Nixy realm, set this if you want to be able to filter your apps (e.g. when you have different loadbalancers which should expose different apps)
    # You will also need to set "NIXY_REALM" label at your app to be included in generated conf
    realm = ""
    
    # Nginx
    nginx_config = "/etc/nginx/nginx.conf"
    nginx_template = "/etc/nginx/nginx.tmpl"
    nginx_cmd = "nginx" # optionally "openresty" or "docker exec nginx nginx"
    nginx_ignore_check = false # optionally disable nginx config test. Health check will always show OK.
    #left_delimiter = "{{" # if you want to change the default template delimiters
    #right_delimiter = "}}" # if you want to change the default template delimiters
    
    # Statsd settings
    [statsd]
    addr = "localhost:8125" # optional for statistics
    #namespace = "nixy.my_mesos_cluster"
    #sample_rate = 100
    
  3. Optionally edit the nginx template (default on ubuntu is /etc/nginx/nginx.tmpl)

  4. Install nginx or openresty and start the service.

    • Or if you prefer running inside Docker: "docker run -d --name nginx -p 7000:7000 -v /etc/nginx:/etc/nginx nginx". You will also need to change config "nginx_cmd" to "docker exec nginx nginx" for reloads to work correctly in this case.
  5. Start nixy! (service nixy start)

Using Nixy

Routing is based on the HTTP Host header matching app ID by default.

If apps are organized under a directory structure the directory will become the root subdomain.

This is easy to change and customize to your own choosing by editing the nginx.tmpl file. For example if you prefer routing based on uri instead of subdomains take a look at nginx-path.tmpl.

Example to access your apps /bar1, /bar2, /foo/bar3 running inside Mesos and Marathon:

curl -i localhost/ -H 'Host: bar1.example.com'
curl -i localhost/ -H 'Host: bar2.example.com'
curl -i localhost/ -H 'Host: bar3.foo.example.com'

Assuming you have configured nginx on port 80.

To set a custom subdomain for an application

Deploy your app to Marathon setting a custom label called subdomain:

"labels": {
    "subdomain": "foobar"
},

This will override the Host for that app and replace it with foobar as the new subdomain/host.

It's also possible to add multiple subdomains to a single app, dividing by a space character.

"labels": {
    "subdomain": "foo bar"
},

This will now match both foo and bar as the new subdomain/host.

Template

Nixy uses the standard Go (Golang) template package to generate its config. It's a powerful and easy to use language to fully customize the nginx config. The default template is meant to be a working base that adds some sane defaults for Nginx. If needed just extend it or modify to suite your environment the best.

If you are unsure of what variables you can use inside your template just do a GET /v1/config and you will receive a JSON response of everything available. All labels and environment variables are available. Other options could be to enable websockets, HTTP/2, SSL/TLS, or to control ports, logging, load balancing method, or any other custom settings your applications need.

HTTP Load Balancing / Proxy

Examples:

Add some ACL rules to block traffic from outside the internal network? Add a Label called internal to your app and the following snippet to your template:

{{- if $app.Labels.internal}}
# allow anyone from local network.
allow 10.0.0.0/8;
# block everyone else
deny all;
{{- end }}

Optionally, add dynamically which network that have access to the same label:

{{- if $app.Labels.internal}}
# allow anyone from local network.
allow {{ $app.Labels.internal }};
# block everyone else
deny all;
{{- end }}

Add a custom http header based on an Environment variable inside your app?

{{- if $app.Env.APP_ENV}}
# could be dev, stage, production...
add_header X-Environment {{ $app.Env.APP_ENV }} always;
{{- end}}

Additional template methods

contains

Wrapper for strings.Contains. Contains reports whether substr is within string.

{{if contains $host "www" }}
hasPrefix

Wrapper for strings.HasPrefix. HasPrefix tests whether the string s begins with prefix.

{{if hasPrefix $host "www" }}
hasSuffix

Wrapper for strings.HasSuffix. HasSuffix tests whether the string s ends with suffix.

{{if hasSuffix $host ".com" }}
split

Wrapper for strings.Split. Splits the input string on the separating string and returns a slice of substrings.

{{- $url := split "localhost:8080" ":" }}
    host: {{index $url 0}}
    port: {{index $url 1}}
join

Alias for the strings.Join function.

apps: {{join $applist ","}}
trim

Alias for the strings.Trim function.

host: {{trim ".app.test.com." "."}}
replace

Alias for the strings.Replace function.

{{$host := "app/test/com"}}
host = {{replace $host "/" "." -1}}
getenv

Wrapper for os.Getenv. Retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present.

hostname: {{getenv "HOSTNAME"}}
datetime

Alias for time.Now

# Generated by nixy {{datetime}}

MergeAppsByLabel

Sometimes it is useful to implement the same service with apps within marathon. In this case you can use .MergeAppsByLabel("some-label") instead of .Apps in your template to merge multiple apps into a single service.

For example if the following apps running in marathon implement the same API:

my-service-a my-service-b

And they both have the label servicename=my-service you could use MergeAppsByLabel("servicename") to access both implementations as nixy.marathon.mesos:12345.

  • When the apps are merged, Labels from each original app are added to each Task from that original app. This is necessary if you want to have implementation specific labels. For example, if one implementation is faster, we could route more traffic there.

TCP/UDP Load Balancing / Proxy

It is possible to use Nixy to configure nginx as a proxy for TCP or UDP traffic.

Please check the nginx-stream.tmpl example template. It assumes you have configured PortDefinitions correctly for all your services in Marathon.

Latest versions of Nginx open-source comes with streaming by default. If you are running version 1.9 you will need to compile it with --with-stream manually.

Nixy API

  • GET / prints nixy version.
  • GET /v1/config JSON response with all variables available inside the template.
  • GET /v1/reload manually trigger a new config reload.
  • GET /v1/health JSON response with health status of template, nginx config and Marathon endpoints available.
  • GET /v1/metrics Prometheus metrics endpoint.

Nagios Monitoring

In case you want to monitor nixy using Nagios (or compatible monitoring) you can use the included check_nixy plugin.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].