Marathon中的网络和端口

BRIDGE networking: 应用于Docker Application.

USER networking:  应用于Docker Application.适合于使用自定义docker网络的情况。

HOST networking: 应用与Docker Application和非Docker Application。

containerPort: 用于容器部署时,在bridge或者user模式网络下 ,指定容器里面的具体端口。

hostPort:指服务绑定到主机上的端口,使用bridge或者user网络模式时,通过撇脂port mapping来映射主机端口到容器端口,在host网络模式是,默认要求的端口就是主机端口。注意,只有主机端口可以通过环境变量被获取到。

servicePort:在marathon里面创建一个新应用时,你可能会分配一个或多个服务给该应用, 可以指定所有的合法端口或者指定为0让marathon来自动分配服务端口。如果你自己指定服务端口,必须确保该端口在所有应用中唯一。

portMapping: 在Docker Bridge模式,portMapping对于需要从外部访问容器内服务来说是必须的,每个端口需要有一条记录,一条记录包含4个元素:host port, container port, service port and protocol。

  • Location in app definition: { "container": { "portMappings": [ <port-mapping>... ], ... }, ... }
  • Used in conjunction with container and container/bridge mode networking.
  • requirePorts does not apply to portMappings

ports: 在host网络模式下使用,ports数组用来定义端口,并且需要作为resurce offer来考虑。只有在portMapping没有指定时才需要。ports或者portDefinitions只需要定义一个。

portDefinitions: 只在host网络模式下,没有指定portMapping时使用。用来代替ports数组的,可以指定 port name, protocol and labels。

  • Location in app definition: { "portDefinitions": [ <port-definition>... ], "requirePorts": <bool>, ... }
  • Used in conjunction with host mode networking.
  • requirePorts applies to portDefinitions.

protocol:  tcp或者/和udp,当Docker容器使用BRIDGE or USER网络模式时,作为portMapping的一部分使用。

requirePorts: 设为true的时候要求在验证在收到的resource offer里面有相应的配置的端口,在BRIDGE or USER网络模式时不使用该配置。

VIPS:  如果使用DC/OS集群,可以使用VIPs来简化端口管理,VIPs简化了集群内部应用之间的通信,实现了面向服务的架构,VIPs将一个单一地址的流量映射到多个地址和端口上。

vip包含3个组成部分:Private virtual IP address, Port (a port which the service is available on), Service name.

vip按如下格式转换的:

<service-name>.marathon.l4lb.thisdcos.directory:<port>
{
  "id": "/my-service",
  "cmd": "sleep 10",
  "cpus": 1,
  "portDefinitions": [
    {
      "protocol": "tcp",
      "port": 5555,
      "labels": {
        "VIP_0": "/my-service:5555"
      },
      "name": "my-vip"
    }
  ]
}

在上面这段设置中,DCOS集群内部APP可以通过my-service.marathon.l4lb.thisdcos.directory:5555来访问服务。

 To view the VIP for Kafka, run

dcos kafka endpoints broker

 from the DC/OS CLI.

猜你喜欢

转载自my.oschina.net/u/2449787/blog/1628707