reorganization-edit docs for WP

This commit is contained in:
Anita Buehrle committed 2016-03-02 13:54:05 -06:00
1 parent 532a6b69d9
commit bdc9eae000
59 files changed
+3184 -2148

No files matched your search

+88
View File
@@ -0,0 +1,88 @@
---
title: Isolating Applications on a Weave Network
layout: default
---
A single Weave network can host multiple, isolated applications where each application's containers are able
to communicate with each other, but not with the containers of other applications.
To isolate applications, you can make use of `isolation-through-subnets` technique.
This common strategy is an example of how with Weave many of your `on metal`
techniques can still be used to deploy applications to a container network.
To begin isolating an application (or parts of an application),
configure Weave's IP allocator to manage multiple subnets.
Using [the netcat example](/site/using-weave/deploying-applications.md), configure multiple subsets:
~~~bash
host1$ weave launch --ipalloc-range 10.2.0.0/16 --ipalloc-default-subnet 10.2.1.0/24
host1$ eval $(weave env)
host2$ weave launch --ipalloc-range 10.2.0.0/16 --ipalloc-default-subnet 10.2.1.0/24 $HOST1
host2$ eval $(weave env)
~~~
This delegates the entire 10.2.0.0/16 subnet to Weave, and instructs
it to allocate from 10.2.1.0/24 within that, if a specific subnet is not
specified.
Next, launch the two netcat containers onto the default subnet:
~~~bash
host1$ docker run --name a1 -ti ubuntu
host2$ docker run --name a2 -ti ubuntu
~~~
And then to test the isolation, launch a few more containers onto a different subnet:
~~~bash
host1$ docker run -e WEAVE_CIDR=net:10.2.2.0/24 --name b1 -ti ubuntu
host2$ docker run -e WEAVE_CIDR=net:10.2.2.0.24 --name b2 -ti ubuntu
~~~
Ping each container to confirm that they can talk to each other, but not to the containers of our first subnet:
~~~bash
root@b1:/# ping -c 1 -q b2
PING b2.weave.local (10.2.2.128) 56(84) bytes of data.
--- b2.weave.local ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.338/1.338/1.338/0.000 ms
~~~
~~~bash
root@b1:/# ping -c 1 -q a1
PING a1.weave.local (10.2.1.2) 56(84) bytes of data.
--- a1.weave.local ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
~~~
~~~bash
root@b1:/# ping -c 1 -q a2
PING a2.weave.local (10.2.1.130) 56(84) bytes of data.
--- a2.weave.local ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
~~~
If required, a container can also be attached to multiple subnets when it is started using:
~~~bash
host1$ docker run -e WEAVE_CIDR="net:default net:10.2.2.0/24" -ti ubuntu
~~~
`net:default` is used to request the allocation of an address from the default subnet in addition to one from an explicitly specified range.
>>**Important:** Containers must be prevented from capturing and injecting raw network packets - this can be accomplished by starting them with the `--cap-drop net_raw` option.
>>Note: By default docker permits communication between containers on the same host, via their docker-assigned IP addresses. For complete
isolation between application containers, that feature needs to be disabled by [setting `--icc=false`](https://docs.docker.com/engine/userguide/networking/default_network/container-communication/#communication-between-containers) in the docker daemon configuration.
**See Also**
* [Managing Services in Weave: Exporting, Importing, Binding and Routing](/site/using-weave/service-management.md)
* [Exposing Services to the Outside World] (/site/using-weave/service-export.md)
+117
View File
@@ -0,0 +1,117 @@
---
title: Deploying Applications To Weave Net
layout: default
---
This section contains the following topics:
* [Launching Weave Net](#launching)
* [Creating Peer Connections Between Hosts](#peer-connections)
* [Testing Container Communications](#testing)
* [Starting the Netcat Service](#start-netcat)
###<a name="launching"></a>Launching Weave Net
Before launching Weave and deploying your apps, ensure that Docker is [installed]( https://docs.docker.com/engine/installation/) on both hosts.
On `$HOST1` run:
host1$ weave launch
host1$ eval $(weave env)
host1$ docker run --name a1 -ti ubuntu
Where,
* The first line runs Weave.
* The second line configures the Weave environment, so that containers launched via the Docker command line are automatically attached to the Weave network, and,
* The third line runs the application container using [Docker commands]( https://docs.Docker.com/engine/reference/commandline/daemon/).
>>**Note:** If the first command results in an error like
`http:///var/run/Docker.sock/v1.19/containers/create: dial unix
/var/run/Docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?` then you likely need to be 'root' in order to connect to the Docker daemon. If so, run the above and all subsequent commands in a *single* root shell (e.g. one created with `sudo -s`). Do *not* prefix individual commands with `sudo`, since some commands modify environment entries and hence they all need to be executed from the same shell.
>>**Important!** if you are running the Weave Docker Network Plugin do not run `eval $(weave env)`. See [Using the Weave Net Docker Network Plugin](/site/pluing/weave-plugin-how-to.md) for more information.
Weave must be launched once per host. The relevant container images will be pulled down from Docker Hub on demand during `weave launch`.
You can also preload the images by running `weave setup`. Preloaded images are useful for automated deployments, and ensure there are no delays during later operations.
If you are deploying an application that consists of more than one container to the same host, launch them one after another using `docker run`, as appropriate.
###<a name="peer-connections"></a>Creating Peer Connections Between Hosts
To launch Weave on an additional host and create a peer connections by running the following:
host2$ weave launch $HOST1
host2$ eval $(weave env)
host2$ docker run --name a2 -ti ubuntu
As noted above, the same steps are repeated for `$HOST2`. The only difference, besides the application container’s name, is that `$HOST2` is told to peer with Weave on `$HOST1` during launch.
You can also peer with other hosts by specifying the IP address, and a `:port` by which `$HOST2` can reach `$HOST1`.
>>**Note:** If there is a firewall between `$HOST1` and `$HOST2`, you must permit traffic to flow through TCP 6783 and UDP 6783/6798, which are Weave’s control nd data ports.
There are a number of different ways that you can specify peers on a Weave network. You can launch Weave on `$HOST1` and then peer with `$HOST2`, or you can launch on `$HOST2` and peer with `$HOST1` or you can tell both hosts about each other at launch. The order in which peers are specified is not important. Weave automatically (re)connects to peers when they become available.
####Specifying Multiple Peers at Launch
To specify multiple peers, supply a list of addresses to which you want to connect, all separated by spaces.
For example:
~~~bash
`host2$:weave launch` <ip address> <ip address>
~~~
Peers can also be dynamically added. See [Adding Hosts Dynamically](/site/using-weave/finding-adding-hosts-dynamically.md) for more information.
###<a name="testing"></a>Testing Container Communications
With two containers running on separate hosts, test that both containers are able to find and communicate with one another using ping.
From the container started on `$HOST1`...
root@a1:/# ping -c 1 -q a2
PING a2.weave.local (10.40.0.2) 56(84) bytes of data.
--- a2.weave.local ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.341/0.341/0.341/0.000 ms
Similarly, in the container started on `$HOST2`...
root@a2:/# ping -c 1 -q a1
PING a1.weave.local (10.32.0.2) 56(84) bytes of data.
--- a1.weave.local ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.366/0.366/0.366/0.000 ms
###<a name="start-netcat"></a>Starting the Netcat Service
The `netcat` service can be started using the following commands:
~~~bash
root@a1:/# nc -lk -p 4422
~~~
and then connected to from the another container on `$HOST2` using:
~~~bash
root@a2:/# echo 'Hello, world.' | nc a1 4422
~~~
Weave supports *any* protocol, and it doesn't have to be over TCP/IP. For example, a netcat UDP service can also be run by using the following:
~~~bash
root@a1:/# nc -lu -p 5533
root@a2:/# echo 'Hello, world.' | nc -u a1 5533
~~~
**See Also**
* [Installing Weave Net](/site/installing-weave.md)
* [Using Fastdp With Weave](/site/fastdp/using-fastdp.md)
* [Using the Weave Net Docker Network Plugin](/site/plugin/weave-plugin-how-to.md)
@@ -0,0 +1,55 @@
---
title: Dynamically Attaching and Detaching Applications
layout: default
---
When containers may not know the network to which they will be attached, Weave enables you to dynamically attach and detach containers to and from a given network, even when a container is already running.
To illustrate these scenarios, imagine a netcat service running in a container on $host1 and you need to attach it to another subnet. To attach the netcat service container to a given subnet run:
host1$ C=$(docker run -e WEAVE_CIDR=none -dti ubuntu)
host1$ weave attach $C
10.2.1.3
Where,
* `C=$(Docker run -e WEAVE_CIDR=none -dti ubuntu)` is a variable for the subnet on which to attach
* `weave attach` – the Weave command to attach to the specified subnet, which takes the variable for the subnet
* `10.2.1.3` - the allocated IP address output by `weave attach` and in this case, represents the default subnet
>>Note If you are using the Weave Docker API proxy, it will have modified `DOCKER_HOST` to point to the proxy and therefore you will have to pass `-e WEAVE_CIDR=none` to start a container that _doesn't_ get automatically attached to the weave network for the purposes of this example.
###Dynamically Detaching Containers
A container can be detached from a subnet, by using the `weave detach` command:
host1$ weave detach $C
10.2.1.3
You can also detach a container from one network and then attach it to a different one:
host1$ weave detach net:default $C
10.2.1.3
host1$ weave attach net:10.2.2.0/24 $C
10.2.2.3
or, attach a container to multiple application networks, effectively sharing the same container between applications:
host1$ weave attach net:default
10.2.1.3
host1$ weave attach net:10.2.2.0/24
10.2.2.3
Finally, multiple addresses can be attached or detached using a single command:
host1$ weave attach net:default net:10.2.2.0/24 net:10.2.3.0/24 $C
10.2.1.3 10.2.2.3 10.2.3.1
host1$ weave detach net:default net:10.2.2.0/24 net:10.2.3.0/24 $C
10.2.1.3 10.2.2.3 10.2.3.1
>>**Important!** Any addresses that were dynamically attached will not be re-attached if the container restarts.
**See Also**
* [Adding and Removing Hosts Dynamically](/site/using-weave/finding-adding-hosts-dynamically.md)
@@ -0,0 +1,60 @@
---
title: Adding and Removing Hosts Dynamically
layout: default
---
To add a host to an existing Weave network, simply launch
Weave on the host, and then supply the address of at least
one host. Weave automatically discovers any other hosts in
the network and establishes connections with them if it
can (in order to avoid unnecessary multi-hop routing).
In some situations all existing Weave hosts may be
unreachable from the new host due to firewalls, etc.
However, it is still possible to add the new host,
provided that inverse connections, for example,
from existing hosts to the new hosts, are available.
To accomplish this, launch Weave onto the new host
without supplying any additional addresses. And then, from one
of the existing hosts run:
host# weave connect $NEW_HOST
Other hosts in the Weave network will automatically attempt
to establish connections to the new host as well.
Alternatively, you can also instruct a peer to forget a
particular host specified to it via `weave launch` or
`weave connect` by running:
host# weave forget $DECOMMISSIONED_HOST
This prevents the peer from trying to reconnect to that host
once connectivity to it is lost, and therfore can be used
to administratively remove any decommissioned peers
from the network.
Hosts may also be bulk-replaced. All existing hosts
will be forgotten, and the new hosts will be added:
host# weave connect --replace $NEW_HOST1 $NEW_HOST2
For complete control over the peer topology, automatic
discovery can be disabled using the `--no-discovery`
option with `weave launch`.
If discovery if disabled, Weave only connects to the
addresses specified at launch time and with `weave connect`.
A list of all hosts that a peer has been asked to connect
to with `weave launch` and `weave connect`
can be obtained with
host# weave status targets
**See Also**
* [Enabling Multi-Cloud, Multi-Hop Networking and Routing](/site/using-weave/multi-cloud-multi-hop.md)
* [Stopping and Removing Peers](/site/ipam/stop-remove-peers-ipam.md)
@@ -0,0 +1,47 @@
---
title: Integrating a Host Network with Weave
layout: default
---
Weave application networks can be integrated with an external host network, establishing connectivity between the host and with application containers running anywhere.
For example, returning to the [netcat example]( /site/using-weave/intro-example.md), you’ve now decided that you need to have the application containers that are running on `$HOST2` accessible by other hosts and containers.
On `$HOST2` run:
host2$ weave expose
10.2.1.132
This command grants the host access to all of the application containers in the default subnet. An IP address is allocated by Weave especially for that purpose, and is returned after running `weave expose`.
Now you are able to ping the host:
host2$ ping 10.2.1.132
And you can also ping the `a1` netcat application container residing on `$HOST1`:
host2$ ping $(weave dns-lookup a1)
###Exposing Multiple Subnets
Multiple subnet addresses can be exposed or hidden with a single command:
host2$ weave expose net:default net:10.2.2.0/24
10.2.1.132 10.2.2.130
host2$ weave hide net:default net:10.2.2.0/24
10.2.1.132 10.2.2.130
###Adding Exposed Addresses to weavedns
Exposed addresses can also be added to `weavedns` by supplying fully qualified domain names:
host2$ weave expose -h exposed.weave.local
10.2.1.132
**See Also**
* [Deploying Applications To Weave Net](/site/using-weave/deploying-applications.md)
* [Managing Services in Weave: Exporting, Importing, Binding and Routing](/site/using-weave/service-management.md)
+19
View File
@@ -0,0 +1,19 @@
---
title: Using Weave Net - Example
layout: default
---
Weave Net provides a simple to deploy networking solution for containerized apps. The example described and built upon throughout this `Using Weave Net` section describes how to manage a Weave container network using a sample application which consists of two simple `netcat` services deployed to containers on two separate hosts, and sometimes extended across three hosts.
The following topics are discussed:
* [Deploying Applications to Weave](/site/using-weave/deploying-applications.md)
* [How to Manually Specify IP Addresses and Subnets](/site/using-weave/manual-ip-address.md)
* [Isolating Applications](/site/using-weave/application-isolation.md)
* [Dynamically Attaching and Detaching Containers](/site/using-weave/dynamically-attach-containers.md)
* [Integrating an External Host Network with Weave](/site/using-weave/host-network-integration.md)
* [Exposing Services to the Outside](/site/using-weave/service-export.md)
* [Managing Services in Weave: Importing, Binding and Routing](/site/using-weave/service-management.md)
* [Enabling Multi-cloud Networking and Multi-hop Routing](/site/using-weave/multi-cloud-multi-hop.md)
* [Adding Hosts Dynamically](/site/using-weave/finding-adding-hosts-dynamically.md)
@@ -0,0 +1,76 @@
---
title: Isolating Applications on a Weave Network
layout: default
---
In some instances, you may need to run applications on the same container network, but at the same time keep the applications isolated from one another.
To do this, you need to configure Weave's IP allocator to manage multiple subnets:
~~~bash
host1$ weave launch --ipalloc-range 10.2.0.0/16 --ipalloc-default-subnet 10.2.1.0/24
host1$ eval $(weave env)
host2$ weave launch --ipalloc-range 10.2.0.0/16 --ipalloc-default-subnet 10.2.1.0/24 $HOST1
host2$ eval $(weave env)
~~~
This delegates the entire 10.2.0.0/16 subnet to Weave, and instructs it to allocate from 10.2.1.0/24 within that if no specific subnet is specified.
Now you can launch two containers onto the default subnet:
~~~bash
host1$ docker run --name a1 -ti ubuntu
host2$ docker run --name a2 -ti ubuntu
~~~
And then launch several more containers onto a different subnet:
~~~bash
host1$ docker run -e WEAVE_CIDR=net:10.2.2.0/24 --name b1 -ti ubuntu
host2$ docker run -e WEAVE_CIDR=net:10.2.2.0.24 --name b2 -ti ubuntu
~~~
Ping the containers from each subnet to confirm that they can communicate with each other, but not to the containers of our first subnet:
~~~bash
root@b1:/# ping -c 1 -q b2
PING b2.weave.local (10.2.2.128) 56(84) bytes of data.
--- b2.weave.local ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.338/1.338/1.338/0.000 ms
~~~
~~~bash
root@b1:/# ping -c 1 -q a1
PING a1.weave.local (10.2.1.2) 56(84) bytes of data.
--- a1.weave.local ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
~~~
~~~bash
root@b1:/# ping -c 1 -q a2
PING a2.weave.local (10.2.1.130) 56(84) bytes of data.
--- a2.weave.local ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
~~~
###Attaching Containers to Multiple Subnets and Isolating Applications
A container can also be attached to multiple subnets by using the following command line arguments with `docker run`:
~~~bash
host1$ docker run -e WEAVE_CIDR="net:default net:10.2.2.0/24" -ti ubuntu
~~~
Where,
*`net:default` is used to request the allocation of an address from the default subnet in addition to one from an explicitly specified range.
>>Note: By default Docker permits communication between containers on the same host, via their Docker-assigned IP addresses. For complete isolation between application containers, that feature _must_ to be disabled by [setting `--icc=false`](https://docs.Docker.com/engine/userguide/networking/default_network/container-communication/#communication-between-containers) in the Docker daemon configuration.
>>**Important:!** Containers must not be allowed to capture and inject raw network packets. This can be prevented by starting the containers with the `--cap-drop net_raw` option.
**See Also**
* [Dynamically Attaching and Detaching Applications](/site/using-weave/dynamically-attach-containers.md)
* [Automatic Allocation Across Multiple Subnets](/site/ipam/allocation-multi-ipam.md)
+64
View File
@@ -0,0 +1,64 @@
---
title: Manually Specifying the IP Address of a Container
layout: default
---
Containers are automatically allocated an IP address that is unique across the Weave network. You can see which address was allocated by running, [`weave ps`](/site/troubleshooting.md#weave-status):
host1$ weave ps a1
a7aee7233393 7a:44:d3:11:10:70 10.32.0.2/12
Weave detects when a container has exited and releases its allocated addresses so they can be re-used by the network.
See the [Automatic IP Address Management](/site/ipam/overview-init-ipam.md) and also an explanation of [the basics of IP addressing](/site/ip-addresses/ip-addresses.md) for further details.
Instead of allowing Weave to allocate IP addresses automatically (using IPAM), there may be instances where you need to control a particular container or a cluster by setting an IP address for it.
You can specify an IP address and a network explicitly, using Classless Inter-Domain Routing or [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing).
For example, in the example, $HOST1 and $HOST2, in CIDR notation you could run your containers as follows:
On `$HOST1`:
~~~bash
host1$ Docker run -e WEAVE_CIDR=10.2.1.1/24 -ti ubuntu
root@7ca0f6ecf59f:/#
~~~
And $HOST2:
~~~bash
host2$ Docker run -e WEAVE_CIDR=10.2.1.2/24 -ti ubuntu
root@04c4831fafd3:/#
~~~
Then test that the container on $HOST2 can be reached:
~~~bash
root@7ca0f6ecf59f:/# ping -c 1 -q 10.2.1.2
PING 10.2.1.2 (10.2.1.2): 48 data bytes
--- 10.2.1.2 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/stddev = 1.048/1.048/1.048/0.000 ms
~~~
And do the same in the container on $HOST1:
~~~bash
root@04c4831fafd3:/# ping -c 1 -q 10.2.1.1
PING 10.2.1.1 (10.2.1.1): 48 data bytes
--- 10.2.1.1 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/stddev = 1.034/1.034/1.034/0.000 ms
~~~
The IP addresses and netmasks can be set to anything, but ensure they don’t conflict with any of the IP ranges in use on the hosts or with IP addresses used by any external services to which the hosts or containers may need to connect.
Individual IP addresses given to containers must, of course, be unique. If you pick an address that the automatic allocator has already assigned a warning appears.
**See Also**
* [Managing Services: Exporting, Importing, Binding and Routing](/site/using-weave/service-management.md)
* [Configuring Weave to Explicitly Use an IP Range](/site/ip-addresses/configuring-weave.md)
* [Automatic IP Address Management](/site/ipam/overview-init-ipam.md)
+44
View File
@@ -0,0 +1,44 @@
---
title: Enabling Multi-Cloud, Multi-Hop Networking and Routing
layout: default
---
###Enabling Multi-Cloud Networking
Before multi-cloud networking can be enabled, you must c
onfigure the network to allow connections through Weave's
control and data ports on the Docker hosts. By default, the
control port defaults to TCP 6783, and the data ports to
UDP 6783/6784.
To override Weave’s default ports specify a port using
the `WEAVE_PORT` setting. For example, if WEAVE_PORT is
set to `9000`, then Weave uses TCP 9000 for its control
port and UDP 9000/9001 for its data port.
>>**Important!** It is recommended that all peers be given
the same setting.
###Multi-hop routing
A network of containers across more than two hosts can be
established even when there is only partial connectivity
between the hosts.
Weave routes traffic between containers as long as
there is at least one *path* of connected hosts
between them.
For example, if a Docker host in a local data center can
connect to hosts in GCE and EC2, but the latter two cannot
connect to each other, containers in the latter two can
still communicate and Weave in this instance will route the
traffic via the local data center.
**See Also**
* [Finding and Adding Hosts Dynamically](/site/using-weave/finding-adding-hosts-dynamically.md)
@@ -0,0 +1,44 @@
---
title: Securing Containers Across Untrusted Networks
layout: default
---
To connect containers across untrusted networks, Weave peers can be instructed to encrypt traffic by supplying a `--password` option or by using the `WEAVE_PASSWORD` environment variable during `weave launch`.
For example:
host1$ weave launch --password wfvAwt7sj
or
host1$ export WEAVE_PASSWORD=wfvAwt7sj
host1$ weave launch
>NOTE: The command line option takes precedence over the environment variable._
> To avoid leaking your password via the kernel process table or your
> shell history, we recommend you store it in a file and capture it
> in a shell variable prior to launching weave: `export
> WEAVE_PASSWORD=$(cat /path/to/password-file)`
To guard against dictionary attacks, the password needs to be reasonably strong with at least 50 bits of entropy is recommended. An easy way to generate a random password that satisfies this requirement is:
< /dev/urandom tr -dc A-Za-z0-9 | head -c9 ; echo
The same password must be specified for all Weave peers, by default both control and data plane traffic will then use authenticated encryption.
If some of your peers are co-located in a trusted network (for example within the boundary of your own datacenter) you can use the `--trusted-subnets` argument to `weave launch` to selectively disable data plane encryption as an optimization.
Both peers must consider the other to be in a trusted subnet for this to take place - if they do not agree, Weave [falls back to a slower method]( /site/fastdp/using-fastdp.md) for transporting data between peers, since fast datapath does not support encryption.
Be aware that:
* Containers will be able to access the router REST API if fast datapath is disabled. You can prevent this by setting:
[`icc=false`](https://docs.docker.com/engine/userguide/networking/default_network/container-communication/#communication-between-containers)
* Containers are able to access the router control and data plane
ports, but this can be mitigated by enabling encryption.
**See Also**
* [Using Encryption With Weave](/site/encryption/crypto-overview.md)
+39
View File
@@ -0,0 +1,39 @@
---
title: Exposing Services to the Outside World
layout: default
---
Services running in containers on a Weave network can be made
accessible to the outside world (and, more generally, to other networks)
from any Weave host, irrespective of where the service containers are
located.
Returning to the netcat example service, described in [Deploying Applications]( /site/using-weave/deploying-applications.md),
you can expose the netcat service running on `HOST1` and make it accessible to the outside world via `$HOST2`.
First, expose the application network to `$HOST2`, as explained in [Integrating a Host Network with a Weave](/site/using-weave/host-network-integration.md):
host2$ weave expose
10.2.1.132
Then add a NAT rule that routes the traffic from the outside world to the destination container service.
host2$ iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 2211 \
-j DNAT --to-destination $(weave dns-lookup a1):4422
In this example, it is assumed that the "outside world" is connecting to `$HOST2` via 'eth0'. The TCP traffic to port 2211 on the external IPs will be routed to the 'nc' service running on port 4422 in the container a1.
With the above in place, you can connect to the 'nc' service from anywhere using:
echo 'Hello, world.' | nc $HOST2 2211
>>**Note:** Due to the way routing is handled in the Linux kernel, this won't work when run *on* `$HOST2`.
Similar NAT rules to the above can be used to expose services not just to the outside world but also to other, internal, networks.
**See Also**
* [Using Weave Net](/site/using-weave/intro-example.md)
* [Managing Services in Weave: Exporting, Importing, Binding and Routing](/site/using-weave/service-management.md)
+116
View File
@@ -0,0 +1,116 @@
---
title: Managing Services in Weave - Exporting, Importing, Binding and Routing
layout: default
---
This section contains the following topics:
* [Exporting Services](#exporting)
* [Importing Services](#importing)
* [Binding Services](#binding)
* [Routing Services](#routing)
* [Dynamically Changing Service Locations](#change-location)
###<a name="exporting"></a> Exporting Services
Services running in containers on a Weave network can be made accessible to the outside world (and, more generally, to other networks) from any Weave host, regardless of where the service containers are located.
Turning back to the netcat example, your netcat service, which is running in a container on `$HOST1`, needs to be accessible to the outside world via `$HOST2`.
To do this, expose the application network to `$HOST2`, as explained in [Host Network Integration](/site/using-weave/host-network-integration.md) by running:
host2$ weave expose
10.2.1.132
Then add a NAT rule to route from the outside world to the destination container service.
host2$ iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 2211 \
-j DNAT --to-destination $(weave dns-lookup a1):4422
Here it is assumed that the "outside world" is connecting to `$HOST2` via 'eth0'. The TCP traffic to port 2211 on the external IPs will be routed to the 'nc' service, running in the a1 container and listening on port 4422.
With the above in place, you are ready to connect to the 'nc' service from anywhere using:
echo 'Hello, world.' | nc $HOST2 2211
>>**Note:** Due to the way routing is handled in the Linux kernel, this won't work when run *on* `$HOST2`.
Similar NAT rules to the above can used to expose services not just to the outside world but also other, internal, networks.
###<a name="importing"></a>Importing Services
Applications running in containers on a Weave network can be given access to services, which are only reachable from certain
Weave hosts, regardless of where the actual application containers are located.
Using the netcat service example described in
[Deploying Applications](/site/using-weave/deploying-applications.md), and expanding upon it, you now decide to add a third containerized netcat service. This additional netcat service runs on `$HOST3`, and listens on port 2211, but it is not on the Weave network.
An additional caveat is that `$HOST3` can only be reached from `$HOST1`, which is not accessible via `$HOST2`. Nonetheless, you still need to make the `$HOST3` service available to an application that is running in a container on `$HOST2`.
To satisfy this scenario, first expose the [application network to the host](/site/using-weave/host-network-integration.md) by running the following on `$HOST1`:
host1$ weave expose -h host1.weave.local
10.2.1.3
Then add a NAT rule, which routes from the above IP to the destination service.
host1$ iptables -t nat -A PREROUTING -p tcp -d 10.2.1.3 --dport 3322 \
-j DNAT --to-destination $HOST3:2211
This allows any application container to reach the service by connecting to 10.2.1.3:3322. So if `$HOST3` is running a
netcat service on port 2211:
host3$ nc -lk -p 2211
You can now connect to it from the application container running on `$HOST2` using:
root@a2:/# echo 'Hello, world.' | nc host1 3322
Note that you should be able to run this command from any application container.
###<a name="binding"></a>Binding Services
Importing a service provides a degree of indirection that allows late and dynamic binding, similar to what can be achieved with a proxy.
Referring back to the netcat services example that is running on three hosts (as explained in Importing Services above), the application containers are completely unaware that the service they are accessing at `10.2.1.3:3322` actually resides on `$HOST3:2211`.
You can point application containers to another service location by changing the above NAT rule, without altering the applications.
###<a name="routing"></a>Routing Services
You can combine the service export and service import features to establish connectivity between applications and services residing on disjointed networks, even if those networks are separated by firewalls and have overlapping IP ranges.
Each network imports its services into Weave, while at the same time, exports from Weave any services that are required by its applications. In this scenario, there are no application containers (although, there could be). Weave is acting as an address translation and routing facility, and uses the Weave container network as an intermediary.
Expanding on the [netcat example](/site/using-weave/deploying-applications.md), you can also import an additional netcat service running on `$HOST3` into Weave via `$HOST1`.
Begin importing the service onto `$HOST2` by first exposing the application network:
host2$ weave expose
10.2.1.3
Then add a NAT rule which routes traffic from the `$HOST2` network (i.e. anything which can connect to `$HOST2`) to the service endpoint on the Weave network:
host2$ iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 4433 \
-j DNAT --to-destination 10.2.1.3:3322
Now any host on the same network as `$HOST2` is able to access the service:
echo 'Hello, world.' | nc $HOST2 4433
###<a name="change-location"></a>Dynamically Changing Service Locations
Furthermore, as explained in Binding Services, service locations can be dynamically altered without having to change any of the applications that access them.
For example, you can move the netcat service to `$HOST4:2211` and it will retain its 10.2.1.3:3322 endpoint on the Weave network.
**See Also**
* [Adding and Removing Hosts Dynamically](/site/using-weave/finding-adding-hosts-dynamically.md)
* [Enabling Multi-Cloud, Multi-Hop Networking and Routing](/site/using-weave/multi-cloud-multi-hop.md)