Skip to content

Commit

Permalink
docs: describe order of ip precedence and new label option
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan committed Oct 9, 2022
1 parent 3cfba8a commit b711d66
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ GLOBAL OPTIONS:
Most important are the `bind-ip` and `redis-addr` flags.

## IP Binding

There are a number of ways to set the IP published to traefik. Below is the
order of precedence (highest first) and detailed descriptions of each setting.

1. `kop.<service name>.bind.ip` label
2. `kop.bind.ip` label
3. Container networking IP
4. `--bind-ip` CLI flag
5. `BIND_IP` env var
6. Auto-detected host IP

### bind-ip

Since your upstream docker nodes are external to your primary traefik server,
Expand All @@ -118,14 +130,26 @@ When using host networking this can be auto-detected, however it is advisable in
the majority of cases to manually set this to the desired IP address. This can
be done using the docker image by exporting the `BIND_IP` environment variable.

### traefik-kop service labels

The bind IP can be set via label for each service/container.

Labels can be one of two keys:

- `kop.<service name>.bind.ip=2.2.2.2`
- `kop.bind.ip=2.2.2.2`

For a container with a single exposed service, or where all services use
the same IP, the latter is sufficient.

### Container Networking

If your container is configured to use a network-routable IP address via an
overlay network or CNI plugin, that address will override the `bind-ip`
configuration above when the `traefik.docker.network` label is present on the
service.

### Service port binding
## Service port binding

By default, the service port will be picked up from the container port bindings
if only a single port is bound. For example:
Expand Down Expand Up @@ -161,7 +185,7 @@ service port on the host and tell traefik to bind to *that* port (8088 in the
example above) in the load balancer config, not the internal port (80). This is
so that traefik can reach it over the network.

### Docker API
## Docker API

traefik-kop expects to connect to the Docker host API via a unix socket, by
default at `/var/run/docker.sock`. The location can be overridden via the
Expand Down
8 changes: 8 additions & 0 deletions traefik_kop.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ func getContainerNetworkIP(dockerClient client.APIClient, conf *dynamic.Configur
return networkIP
}

// Check for explicit IP binding set via label
//
// Label can be one of two keys:
// - kop.<service name>.bind.ip = 2.2.2.2
// - kop.bind.ip = 2.2.2.2
//
// For a container with only a single exposed service, or where all services use
// the same IP, the latter is sufficient.
func getKopOverrideBinding(dockerClient client.APIClient, conf *dynamic.Configuration, svcType string, svcName string, hostIP string) (string, bool) {
container, err := findContainerByServiceName(dockerClient, svcType, svcName, getRouterOfService(conf, svcName, svcType))
if err != nil {
Expand Down

0 comments on commit b711d66

Please sign in to comment.