kubernetes具有多个后端端口的负载均衡器

我有一个应用程序与三个不同的后端types。 他们每个人都在不同的端口上听(例如8080,8180,8280)。 现在我想通过使用http://example.com:{8080,8180,8280}来访问它们。 为了安全起见,应该运行每个服务的两个吊舱。

  1. yaml文件应该如何看起来像多个后端,他们每个都有不同的端口?
  2. 我可以在同一个文件中包含副本的定义吗? 或者是否有一些在kubernetes主文件,我可以包括其他文件?

要做到这一点,你会创build多个服务,请参阅http://kubernetes.io/docs/user-guide/services/了解详情。

一个例子可能看起来像(使用yaml,你也可以使用json):

 apiVersion: v1 kind: Service metadata: name: yourservice_1 namespace: default labels: component: yourcomponent spec: type: NodePort selector: component: yourcomponent ports: - name: http port: 8080 protocol: TCP --- apiVersion: v1 kind: Service metadata: name: yourservice_2 namespace: default labels: component: yourcomponent spec: type: NodePort selector: component: yourcomponent ports: - name: http port: 8081 protocol: TCP --- Etc. 

并回答你的问题的第二部分:

是在一个文件中有多个定义(可以是服务,可以是任何kubernetes yaml)。

然而,我build议一个单独的服务文件,因为它们通常只装载一次,而另一个文件则用于你的pod定义(因为这个文件的更改频率会更高)。

有一点要注意的多服务定义:在(至lessKubernetes 1.3.5 / 1.3.6,我正在使用的版本),有一个失控的问题,其中select器的某些组合导致kubernetes开始就像许多豆荚,因为它可以。 为了防止这种情况:testing和实验。 只要你避免这种情况,它就会工作。

单个服务入口点也可以被使用,并且可以被定义为:

 apiVersion: v1 kind: Service metadata: name: yourservice_1 namespace: default labels: component: yourcomponent spec: type: NodePort selector: component: yourcomponent ports: - name: http port: 8080 protocol: TCP - name: http2 port: 8081 protocol: TCP - name: http2 port: 8082 protocol: TCP