Kuberenetes系统学习(三)-----掌握Service

一、Service的详细作用
负载均衡,外网访问,DNS服务的搭建,Ingress7层路由机制

yaml格式的Service定义文件的完整内容如下:

apiVersion: v1                      //Required
kind: Service                       //Required
metadata:                           //Required
	name: string                    //Required
	namespace: string               //Required
	labels:
		- name: string
	annotations:
		- name: string
spec:                                //Required
	selector: []                     //Required
	type: string                     //Required
	clusterIP: string
	sessionAffinity: string
	ports:
	- name: string
	- protocol: string
	- port: int
	- targetPort: init
	- nodePort: int
status:	
	loadBalancer:
		ingress:
			ip: string
			hostname: string  

创建服务

kubectl create -f servicexx.yaml

获得Pod的IP地址:

kubectl get pods -l app=webapp -o yaml |grep podIP

kubernetes提供了两种负载分发策略:RoundRobin和SessionAffinity

RoundRobin:轮询模式,轮询将请求转发到后端各个pod上
SessionAffinity:基于客户端IP地址进行会话保持的模式
可以通过service.spec.sessionAffinity=ClientIP来启用SessionAffinity策略

集群的自动添加,我们可以用

kubectl scale rc xxxxx --replicas = 2

更多技术文章请关注公众号:架构师Plus,
扫码添加
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章