Inter-FaaS platform networking

To make all functions of different platforms able to talk together, we need to set up a proper container network. The demo project discussed in this chapter is not a simple FaaS example. It is a complex scenario where functions are allowed to call other functions on the different FaaS platforms.

Normally, on some serverless platforms such as Lambda, we may sometimes assume that all functions run on the flat network of the provider. In contrast, when we run functions on our own platforms, we could segment the networks ourselves and function networking will become a challenge. However, networking will be relatively simple because the networking model in Docker and Swarm is the flat network.

How can we achieve this? By the following:

  1. We create an attachable Swarm-scoped network
  2. We start a FaaS framework and make its gateway attach to that network
  3. We also need to tell the framework that it must attach that network to every container it created

In OpenFaas, it allows you to create a function to run on a specific network. In OpenWhisk, we can specify this with a configuration of an invoker. For the Fn Project, we need an additional hack. Here's the change required to patch to Fn in order to make it able to attach function containers to a specified network (FN_NETWORK):

var networkingConfig *docker.NetworkingConfig
fnNetwork := os.Getenv("FN_NETWORK")
if fnNetwork != "" {
log.Debugf("Env FN_NETWORK found: %s. Create container %s with network.",
fnNetwork, task.Id())
networkingConfig = docker.NetworkingConfig{
EndpointsConfig: map[string]*docker.EndpointConfig{
fnNetwork: {
Aliases: []string{task.Id()},
},
},
}
}
container := docker.CreateContainerOptions{
Name: task.Id(),
Config: docker.Config{
Env: envvars,
Cmd: cmd,
Memory: int64(task.Memory()),
MemorySwap: int64(task.Memory()),
KernelMemory: int64(task.Memory()),
CPUShares: drv.conf.CPUShares,
Hostname: drv.hostname,
Image: task.Image(),
Volumes: map[string]struct{}{},
OpenStdin: true,
AttachStdin: true,
StdinOnce: true,
},
HostConfig: docker.HostConfig{
LogConfig: docker.LogConfig{
Type: "none",
},
},
NetworkingConfig: networkingConfig,
Context: ctx,
}

The version with the function networking patch is available at https://github.com/chanwit/fn.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset