首页 > 其他分享 >Istio ServiceEntry实例

Istio ServiceEntry实例

时间:2022-11-01 14:57:24浏览次数:48  
标签:ServiceEntry 8091 Istio 192.168 nginx 实例 wgs com 2001

服务说明

  • 在网格外部运行有nginx服务,有两个实例

    • Nginx2001:监听地址为 172.29.1.201:8091,Nginx版本为1.20

    • Nginx2002:监听地址为 172.29.1.202:8091,Nginx版本为1.20

    • Nginx2101:监听地址为 172.29.1.203:8091,Nginx版本为1.21
  • 网格内部default名称空间中的pods/client作为客户端访问该服务

主机设置

添加IP地址

~# ip addr add 192.168.174.130/16 dev ens33
~# ip addr add 192.168.174.131/16 dev ens33
~# ip addr add 192.168.174.132/16 dev ens33

查看IP地址

~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq state UP group default qlen 1000
    link/ether 00:0c:29:35:d9:64 brd ff:ff:ff:ff:ff:ff
    inet 192.168.174.121/24 brd 192.168.174.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.174.130/16 scope global ens33
       valid_lft forever preferred_lft forever
    inet 192.168.174.131/16 scope global secondary ens33
       valid_lft forever preferred_lft forever
    inet 192.168.174.132/16 scope global secondary ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe35:d964/64 scope link 
       valid_lft forever preferred_lft forever

部署nginx

docker-compose.yml

version: '3.3'

services:
  nginx2001:
    image: nginx:1.20-alpine
    volumes:
      - ./html/nginx2001:/usr/share/nginx/html/
    networks:
      envoymesh:
        ipv4_address: 172.31.201.11
        aliases:
        - nginx
    expose:
      - "80"
    ports:
      - "192.168.174.130:8091:80"

  nginx2002:
    image: nginx:1.20-alpine
    volumes:
      - ./html/nginx2002:/usr/share/nginx/html/
    networks:
      envoymesh:
        ipv4_address: 172.31.201.12
        aliases:
        - nginx
    expose:
      - "80"
    ports:
      - "192.168.174.131:8091:80"

  nginx2101:
    image: nginx:1.21-alpine
    volumes:
      - ./html/nginx2101:/usr/share/nginx/html/
    networks:
      envoymesh:
        ipv4_address: 172.31.201.13
        aliases:
        - nginx
        - canary
    expose:
      - "80"
    ports:
      - "192.168.174.132:8091:80"

networks:
  envoymesh:
    driver: bridge
    ipam:
      config:
        - subnet: 172.31.201.0/24

运行nginx

# docker-compose up -d
[+] Running 4/4
 ⠿ Network wgs_envoymesh      Created                                                                                                                 0.1s
 ⠿ Container wgs-nginx2101-1  Started                                                                                                                 1.5s
 ⠿ Container wgs-nginx2001-1  Started                                                                                                                 1.6s
 ⠿ Container wgs-nginx2002-1  Started   

访问nginx

~# curl 192.168.174.130:8091
nginx 2001
~# curl 192.168.174.131:8091
nginx 2002
~# curl 192.168.174.132:8091
nginx 2101

部署client

创建client

~# kubectl run client --image=ikubernetes/admin-box -it --rm --restart=Never --command -- /bin/sh
If you don't see a command prompt, try pressing enter.
root@client # 

添加域名解析

root@client # echo "192.168.174.130 nginx.wgs.com" >> /etc/hosts

访问nginx

root@client # while true;do curl nginx.wgs.com:8091; sleep 0.$RANDOM;done
nginx 2001
nginx 2001
nginx 2001

查看kiali

ServiceEntry

serviceentry-nginx.yaml

apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
  name: nginx-external
spec:
  hosts:
  - nginx.wgs.com
  addresses:
  - "192.168.174.130"
  - "192.168.174.131"
  - "192.168.174.132"
  ports:
  - number: 8091
    name: http
    protocol: HTTP
  location: MESH_EXTERNAL
  resolution: STATIC
  endpoints:
  - address: "192.168.174.130"
    ports:
      http: 8091
  - address: "192.168.174.131"
    ports:
      http: 8091
  - address: "192.168.174.132"
    ports:
      http: 8091

destinationrule-nginx.yaml

apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: nginx-external
spec:
  host: nginx.wgs.com
  trafficPolicy:
    loadBalancer:
      consistentHash:
        httpHeaderName: X-User
    connectionPool:
      tcp:
        maxConnections: 10000
        connectTimeout: 10ms
        tcpKeepalive:
          time: 7200s
          interval: 75s
      http:
        http2MaxRequests: 1000
        maxRequestsPerConnection: 10
    outlierDetection:
      maxEjectionPercent: 50
      consecutive5xxErrors: 5
      interval: 2m
      baseEjectionTime: 1m
      minHealthPercent: 40

virtualservice-nginx.yaml

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: nginx-external
spec:
  hosts:
  - nginx.wgs.com
  http:
  - name: falut-injection
    match:
    - headers:
        X-Testing:
          exact: "true"
    route:
    - destination:
        host: nginx.wgs.com
    fault:
      delay:
        percentage:
          value: 5
        fixedDelay: 2s
      abort:
        percentage:
          value: 5
        httpStatus: 555
  - name: nginx-external
    route:
    - destination:
        host: nginx.wgs.com

创建资源

# kubectl apply -f .
serviceentry.networking.istio.io/nginx-external created
destinationrule.networking.istio.io/nginx-external created
virtualservice.networking.istio.io/nginx-external created

查看ServiceEntry

# kubectl get se
NAME             HOSTS               LOCATION        RESOLUTION   AGE
nginx-external   ["nginx.wgs.com"]   MESH_EXTERNAL   STATIC       31s

查看listeners

~# istioctl pc listener client --port 8091
ADDRESS PORT MATCH                                DESTINATION
0.0.0.0 8091 Trans: raw_buffer; App: http/1.1,h2c Route: 8091
0.0.0.0 8091 ALL                                  PassthroughCluster

查看cluster

~# istioctl pc  cluster client --port 8091
SERVICE FQDN      PORT     SUBSET     DIRECTION     TYPE     DESTINATION RULE
nginx.wgs.com     8091     -          outbound      EDS      nginx-external.default

查看endpoint

~# istioctl pc  endpoint client --port 8091
ENDPOINT                 STATUS      OUTLIER CHECK     CLUSTER
192.168.174.130:8091     HEALTHY     OK                outbound|8091||nginx.wgs.com
192.168.174.131:8091     HEALTHY     OK                outbound|8091||nginx.wgs.com
192.168.174.132:8091     HEALTHY     OK                outbound|8091||nginx.wgs.com

查看route

~# istioctl pc routes client --name 8091
NAME     DOMAINS                            MATCH     VIRTUAL SERVICE
8091     nginx.wgs.com, 192.168.174.132     /*        nginx-external.default
8091     nginx.wgs.com, 192.168.174.132     /*        nginx-external.default

访问nginx

访问nginx

root@client # while true;do curl  nginx.wgs.com:8091; sleep 0.$RANDOM;done
nginx 2002
nginx 2002
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2101
nginx 2002
nginx 2002
nginx 2001
nginx 2001
nginx 2101
nginx 2101
nginx 2002
nginx 2101

测试一致性hash

root@client # while true;do curl -H "X-user: user1"  nginx.wgs.com:8091; sleep 0.$RANDOM;done
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001

 测试故障注入

root@client # while true;do curl -H "X-Testing: true"  nginx.wgs.com:8091; sleep 0.$RANDOM;done
nginx 2002
nginx 2002
nginx 2002
nginx 2002
nginx 2101
nginx 2002
nginx 2001
nginx 2101
nginx 2101
nginx 2001
nginx 2001
nginx 2001
nginx 2101
nginx 2101
nginx 2002
nginx 2001
nginx 2002
nginx 2001
fault filter abortnginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001
nginx 2001
fault filter abortnginx 2001
nginx 2101
nginx 2101
fault filter abortnginx 2001

标签:ServiceEntry,8091,Istio,192.168,nginx,实例,wgs,com,2001
From: https://www.cnblogs.com/wangguishe/p/16845228.html

相关文章

  • Istio 流量拦截
    Sidecar代理方式简介Kubernetes平台上,EnvoySidecar容器与application容器于同一个Pod中共存,它们共享NETWORK、UTS和IPC等名称空间,因此也共用同一个网络协议栈;EnvoySideca......
  • Spring------Bean的实例化的几种方法
    构造方法提供可访问的构造方法:无参构造方法被调用:如果无参构造方法不存在,将抛出异常BeanCreationException静态工厂在ApplicaytionContext.xml中使用静态工厂的方法......
  • 实例化bean的三种方式
    方式一:构造方法(常用)注意:无参构造方法如果不存在,将抛出异常BeanCreationException方式二:静态工厂注意:配置的区别是配置的bean为工厂类,还要再加一个参数,factory-method=......
  • istio部署demoapp应用 (十四)sidecar
    创建client~#kubectlrunclient--image=ikubernetes/admin-box-it--rm--restart=Never--command--/bin/shIfyoudon'tseeacommandprompt,trypressingen......
  • 大一学生《Web编程基础》期末网页制作 HTML+CSS+JavaScript 网页设计实例 企业网站制
    HTML实例网页代码,本实例适合于初学HTML的同学。该实例里面有设置了css的样式设置,有div的样式格局,这个实例比较全面,有助于同学的学习,本文将介绍如何通过从头开始设计个人......
  • 【降维之NMF】NMF(非负矩阵分解)实例
    数据介绍:NMF人脸数据特征提取目标:已知Olivetti人脸数据共400个,每个数据是64*64大小。由于NMF分解得到的W 矩阵相当于从原始矩阵中提取的特征,那么就可以使用NMF对400......
  • 【降维之PCA】PCA实例
    数据介绍:PCA实现高维数据可视化目标:已知莺尾花数据是4维的,共三类样本(150*4)。使用РСA实现鸢尾花数据进行降维,实现在二维平面上的可视化。PCA可以将具有相关性的高维变......
  • 在完全由Spring管理的环境中使用Spring的Context获取Bean实例
    在大型的应用中,常常会有很灵活的需求,而在使用了框架之后,虽然可以大大提高开发的效率,但同时,也把我们框到一个架子中了。下面先说一下我遇到的问题,事情大概是这样的:@Componen......
  • Istio Policies and Telemetry
    要理解策略和遥测,首先要理解Mixer的架构;[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sUuojjzC-1664190859192)(https://istio.io/docs/conc......
  • Istio(十三):Istio项目实际案例——Online Boutique
    目录一.模块概览二.系统环境三.创建Kubernetes(k8s)集群3.1创建Kubernetes(k8s)集群3.2Kubernetes集群环境四.安装istio4.1安装Istio五.部署onlineBoutique应用5.1部......