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

时间:2017-01-01 23:38:58

标签: docker kubernetes

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

  1. yaml文件应该如何使用多个后端,每个后端都有不同的端口?
  2. 我可以在同一个文件中包含副本的定义吗?或者在kubernetes中是否存在某种主文件,我可以在其中包含其他文件?

1 个答案:

答案 0 :(得分:0)

要执行此操作,您需要创建多项服务,有关详细信息,请参阅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)。

然而,我建议一个单独的服务文件,因为它们通常只会被加载一次,而一个单独的文件用于你的pod定义(因为它会更频繁地改变)。

使用多服务定义需要注意的一点是:在(至少Kubernetes 1.3.5 / 1.3.6,我使用的版本)中,存在一个失控的pod问题,其中选择器的某些组合导致kubernetes开始尽可能多的豆荚。为了防止这种情况:测试和实验。只要你避免这种情况,它就会起作用。

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

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
相关问题