我有一个具有三种不同后端类型的应用程序。他们每个人都在不同的端口上收听(例如8080,8180,8280)。 现在我想使用http://example.com:{8080,8180,8280}
来访问它们。为了安全起见,应该运行每个服务的两个吊舱。kubernetes具有多个后端端口的负载平衡器
- yaml文件应该像多个后端一样,每个后端都有不同的端口?
- 我可以在同一个文件中包含副本的定义吗?或者是否有某种可以包含其他文件的kubernetes主文件?
我有一个具有三种不同后端类型的应用程序。他们每个人都在不同的端口上收听(例如8080,8180,8280)。 现在我想使用http://example.com:{8080,8180,8280}
来访问它们。为了安全起见,应该运行每个服务的两个吊舱。kubernetes具有多个后端端口的负载平衡器
要做到这一点,您将创建多个服务,详情请参阅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
你如何获得所有这些服务的单一入口点?正如原来的问题所述:'http:// example.com' ... –
啊,理解你的问题不同。见答案的第2部分。 –