istio服务案例实践

作者&投稿:廖佳 (若有异议请与网页底部的电邮联系)
~ 一般的服务不需要做过多修改,开启自动注入后,istio会自动注入siderbar等依赖服务和组件。

这里新建一个命名空间(参照前面的文章)进行实验,并设置成默认空间

kubectl config set-context $(kubectl config current-context) --namespace=dwaynt-istio

开启siderbar默认注入,指定dwaynt-istio命名空间:

kubectl label namespace dwaynt-istio istio-injection=enabled

Kubectl apply 部署应用。Siderbar会自动注入到该服务。

helloworld.yaml:

Istio中使用ingressgateway作为入口,创建istio-gress.yaml,创建gateway规则,注意VirtualService中的route host指的是服务的hostname,同一个namespace里面就是service-name。port number要和istio初始化时使用的配置(manifests/profiles/demo.yaml)istio-ingressgateway中的设置对应(我选用的是demo配置),http协议80端口。

apiVersion: networking.istio.io/v1alpha3

kind: Gateway

metadata:

  name: spring-boot-istio-gateway

spec:

  selector:

    istio: ingressgateway

  servers:

    - port:

        number: 80

        name: http-hellogateway

        protocol: HTTP

      hosts:

        - "*"

---

apiVersion: networking.istio.io/v1alpha3

kind: VirtualService

metadata:

  name: helloworld-istio

spec:

  hosts:

    - "www.helloworld.com"

  gateways:

    - spring-boot-istio-gateway

  http:

    - match:

        - uri:

            prefix: /helloworld

      route:

        - destination:

            host: helloworld-master

            port:

              number: 17077

kubectl patch service istio-ingressgateway -n istio-system -p '{"spec":{"type":"NodePort"}}'

export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o 'jsonpath={.items[0].status.hostIP}')

export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')

浏览器通过ip+port访问,路由设置了host,本地绑定域名,通过域名访问

http://www.helloworld.com:31779/helloworld

upstream connect error or disconnect/reset before headers. reset reason: connection failure, transport failure reason: TLS error: 268436501:SSL routines:OPENSSL_internal:SSLV3_ALERT_CERTIFICATE_EXPIRED

解决方法:

重启istio服务

kubectl delete pods istio-egressgateway-65bdddf685-mzzmg istio-ingressgateway-7b545cdbc7-68pgx istiod-864977fd6c-qj75n   -n istio-system

查看集群内dns(找一个在集群内的服务查看容器内的设置):

增加到本地dns(在启动coredns时一般会自动修改/etc/resolve.conf,ubuntu18.04 systemd服务会刷新,所以需要修改该服务的配置):

测试服务请求:

服务地址一般为<service-name>.<namespace>.svc.cluster.local:port

增加一个helloworld-istio服务,和前面的helloworld-master服务区分,helloworld-istio调用helloworld-master服务:

@RestController

public class AController {

    @Autowired

    RestTemplate restTemplate;

    @RequestMapping(value = "/hellosecond/helloworld", method = RequestMethod. GET )

    public Response hello() {

        Response res = new Response();

        String result = restTemplate.getForObject("http://helloworld-master.dwaynt-istio.svc.cluster.local:17077/helloworld", String.class);

        res.setMsg("helloworld-istio-second:" +

                "get from master:" + result);

        return res;

    }

}

helloworld-istio.yaml示例:

apiVersion: v1

kind: Service

metadata:

  name: helloworld-istio

  namespace: dwaynt-istio

  labels:

    verison: "1.0.0"

    env: "test"

spec:

  selector:

    app: helloworld-istio

    release: master

  ports:

      - name: http

        port: 17078

        targetPort: 17002

---

apiVersion: apps/v1

kind: Deployment

metadata:

  name: helloworld-istio

  namespace: dwaynt-istio

spec:

  replicas: 1

  selector:

    matchLabels:

      app: helloworld-istio

      release: master

  template:

    metadata:

      labels:

        app: helloworld-istio

        release: master

        version: "1.0.0"

    spec:

      containers:

        - name: demo-hello-world-istio

          image: dw/demo-hello-world-istio

          imagePullPolicy: IfNotPresent

          ports:

            - name: http

              containerPort: 17078

增加helloworld-istio服务的路由:

apiVersion: networking.istio.io/v1alpha3

kind: VirtualService

metadata:

  name: helloworld-istio

spec:

  hosts:

    - "www.helloworld.com"

  gateways:

    - spring-boot-istio-gateway

  http:

    - match:

        - uri:

            prefix: /hellosecond

      route:

        - destination:

            host: helloworld-istio

            port:

              number: 17078

    - match:

        - uri:

            prefix: /helloworld

      route:

        - destination:

            host: helloworld-master

            port:

              number: 17077

浏览器访问测试:

查看链路:

DestinationRule组件,设置限流和熔断规则

参考: http://dljz.nicethemes.cn/news/show-99078.html

注意,对于HTTP1而言,限制并发数=maxConnections*maxRequestsPerConnection,对于HTTP2而言,限制并发数=http2MaxRequests, outlierDetection是异常检测,熔断机制,baseEjectionTime拒绝服务时间,maxEjectionPercent拒绝比例。

Yaml例子参考,设置hello-istio服务的限流和熔断:

apiVersion: networking.istio.io/v1alpha3

kind: DestinationRule

metadata:

  name: hello-rule

spec:

  host: helloworld-istio

  trafficPolicy:

    connectionPool:

      tcp:

        maxConnections: 1

      http:

        http1MaxPendingRequests: 1

        maxRequestsPerConnection: 1

        http2MaxRequests: 1

    outlierDetection:

      consecutive5xxErrors: 1

      interval: 1s

      baseEjectionTime: 30s

      maxEjectionPercent: 100

Helloworld-istio服务增加一个2.0.0版本:

---

apiVersion: apps/v1

kind: Deployment

metadata:

  name: helloworld-istio-2

  namespace: dwaynt-istio

spec:

  replicas: 1

  selector:

    matchLabels:

      app: helloworld-istio

      release: master

  template:

    metadata:

      labels:

        app: helloworld-istio

        release: master

        version: "2.0.0"

    spec:

      containers:

        - name: demo-hello-world-istio

          image: dw/demo-hello-world-istio-2

          imagePullPolicy: IfNotPresent

          ports:

            - name: http

              containerPort: 17078

应用yaml:

kubectl apply -f helloworld.yaml

多次访问http://www.helloworld.com:31779/hellosecond/helloworld,查看调用链路。默认情况下负载是轮询,平均负载压力:

按比例灰度访问:

修改destinationrule,增加subset:

apiVersion: networking.istio.io/v1alpha3

kind: DestinationRule

metadata:

  name: hello-rule

spec:

  host: helloworld-istio

  trafficPolicy:

    connectionPool:

      tcp:

        maxConnections: 1

      http:

        http1MaxPendingRequests: 1

        maxRequestsPerConnection: 1

        http2MaxRequests: 1

    outlierDetection:

      consecutive5xxErrors: 1

      interval: 1s

      baseEjectionTime: 30s

      maxEjectionPercent: 100

  subsets:

  - labels:

      version: "1.0.0"

    name: v1

  - labels:

      version: "2.0.0"

    name: v2

修改virtualservice,增加比例,v1:v2按照4:1配置:

      route:

        - destination:

            host: helloworld-istio

            subset: v1

            port:

              number: 17078

          weight: 80

        - destination:

            host: helloworld-istio

            subset: v2

            port:

              number: 17078

          weight: 20

测试,测试100次,基本是4:1的负载比例:


永新区17562043643: IM营销的经典案例 -
梅苛瑞白: 耐克在8月19日,向全国各大报纸推出了其连夜赶制的“爱运动,即使它伤了你的心”公关广告.广告依然使用了刘翔的大幅照片,却不再选用其过往奔跑的形象,采用仅是刘翔的平静的面孔及这样一句广告语:“爱比赛,爱拼上所有的尊严,...

永新区17562043643: 哪里有海尔服务营销案例? -
梅苛瑞白: 海尔的营销网络案例分析报告 第一部分:背景介绍 一、海尔集团简介:海尔集团的前身是濒临倒闭的青岛电冰箱总厂,1984...

永新区17562043643: 酒店总机服务案例 -
梅苛瑞白: 酒店案例:总机案例 五一黄金周的一天19:40左右,总机接到一位外地客人打来的电话,他是自己驾车携家人来新昌游玩,而且已在酒店订了房,但天色已黑,不知该如何行车才能到达酒店.总机服务员自认为对本城是最熟悉不过了,于是问清...

永新区17562043643: 人力资源管理案例分析:西门子公司的人力资源开发 -
梅苛瑞白: 1.西门子公司培训具有全覆盖、针对性、计划性的特点,而且培训方式形式多样化.有新员工培训、大学精英培训和在职员工培训.培训的内容根据管理学知识和公司业务的需要而制定,涵盖了业务技能、交流能力和管理能力的广泛领域.同时...

永新区17562043643: 客户关系管理案例分析 -
梅苛瑞白: 1,主次未分,胡子头发一把抓.成本加大,利益减小服务态度,管理机制,有点问题 2 整理信息,注重点,找规律,按科学的调配和服务针对不同的客户3企业要成长,类似人要活着一样,就像营养摄入也有主次,有多少的区分,有时机的区分吧

永新区17562043643: 移动客户服务案例 -
梅苛瑞白: 四川移动SiteView网管系统覆盖四川移动全省范围,包括四川移动办公大楼、地市级区域、成都郊区等区域的网络系统,其中还有部分无线网络.在四川移动的全省网络拓扑中,共有两台中心交换机、数十台windows、Unix服务器和数十台交换...

永新区17562043643: 寻两篇有关管理会计的实际案例 -
梅苛瑞白: 中小型企业会计电算化中的问题及对策随着计算机技术的飞速发展与广泛运用,推动着我国财务领域发生了一场深刻的革命——企业会计电算化.会计电算化是以电子计算机为主的当代电子技术应用到会计信息系统的简称.它首先是实现整个会...

永新区17562043643: 物业管理实务实践考核(案例分析) -
梅苛瑞白: 1、管理处对于李先生的投诉处理的不恰当.物业公司有责任对小区业主进行装修管理,张先生未办理装修手续,作为物业公司应该督促该业主前来办理,而不是一推了之.作为物业公司应该协调两家,处理该事. 2、管理处降低维修收费标准提高经济效益是可行的.市场有供需关系,目前有这么大的市场,供应量增加,就必然导致价格的下降.所以我觉得管理处这样做是可行的.

永新区17562043643: 服务营销的7ps理论的案例都有哪些? -
梅苛瑞白: 一:案例一:经典案例——宝岛眼镜宝岛眼镜成功案例:营销战略的组合应用宝岛眼镜的整体营销战略分成店内及店外.店内的营销就是7P里的Process、People、Physical Evidence.传统的4P营销在对外的使用上仍然是重点.宝岛眼镜...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网