istio案例-tomcat

效果图
在这里插入图片描述

deploy

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-server-vs
spec:
  hosts:
  - "huwq.server.com"
  gateways:
  - gateway-all
  http:
    - route:
        - destination:
            host: my-service.default.svc.cluster.local
            port:
              number: 8080
[root@k8s-master1 rule]# cat Deployment.yaml 
# my-service-v1 Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-service-v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-service
      version: v1
  template:
    metadata:
      labels:
        app: my-service
        version: v1
    spec:
      containers:
      - name: my-service
        image: hub.c.163.com/library/tomcat:7.0
        ports:
        - containerPort: 8080

---

# my-service-v2 Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-service-v2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-service
      version: v2
  template:
    metadata:
      labels:
        app: my-service
        version: v2
    spec:
      containers:
      - name: my-service
        image: hub.c.163.com/library/tomcat:8.0
        ports:
        - containerPort: 8080

---

# my-service-v3 Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-service-v3
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-service
      version: v3
  template:
    metadata:
      labels:
        app: my-service
        version: v3
    spec:
      containers:
      - name: my-service
        image: hub.c.163.com/library/tomcat:9.0
        ports:
        - containerPort: 8080

svc

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-service
  ports:
  - port: 8080
    targetPort: 8080

gw

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: gateway-all
spec:
  # The selector matches the ingress gateway pod labels.
  # If you installed Istio using Helm following the standard documentation, this would be "istio=ingress"
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"

Destination

# my-service Destination Rule
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: my-service
spec:
  host: my-service
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
  - name: v3
    labels:
      version: v3

vs

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-server-vs
spec:
  hosts:
  - "huwq.server.com"
  gateways:
  - gateway-all
  http:
    - route:
        - destination:
            host: my-service.default.svc.cluster.local
            port:
              number: 8080

权重分发

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-server-vs
spec:
  hosts:
  - "huwq.server.com"
  gateways:
  - gateway-all
  http:
  - route:
    - destination:
        host: my-service
        subset: v1
      weight: 100
    - destination:
        host: my-service
        subset: v2
      weight: 0
    - destination:
        host: my-service
        subset: v3
      weight: 0

header 分发

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: my-server-vs
spec:
  hosts:
  - "huwq.server.com"
  gateways:
  - gateway-all
  http:
  - match:
    - headers:
        version:
          exact: "7.0"  # 根据请求头 version 的值来路由
    route:
    - destination:
        host: my-service
        subset: v1
  - match:
    - headers:
        version:
          exact: "8.0"
    route:
    - destination:
        host: my-service
        subset: v2
  - match:
    - headers:
        version:
          exact: "9.0"
    route:
    - destination:
        host: my-service
        subset: v3
  - route:
    - destination:
        host: my-service
        subset: v1  # 默认路由
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值