istio网关暴露之蓝绿

还是和之前一样暴露网关先

cat<<END> out-api.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: out-api-gateway
  namespace: opx
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
END
cat <<END>test-v1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: http-v1
  namespace: opx
  labels:
    server: http-v1
    app: web
spec:
  replicas: 1
  selector:
    matchLabels:
      server: http-v1
      app: web
  template:
    metadata:
      name: http-v1
      labels:
        server: http-v1
        app: web
    spec:
      containers:
      - name: http-v1
        image: registry.cn-shenzhen.aliyuncs.com/jbjb/test:nginx-v01
        ports:
        - containerPort: 80
END

cat test-v2.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: http-v2
  namespace: opx
  labels:
    server: http-v2
    app: web
spec:
  replicas: 1
  selector:
    matchLabels:
      server: http-v2
      app: web
  template:
    metadata:
      name: http-v2
      labels:
        server: http-v2
        app: web
    spec:
      containers:
      - name: http-v2
        image: registry.cn-shenzhen.aliyuncs.com/jbjb/test:nginx-v01
        ports:
        - containerPort: 80

暴露svc
cat svc-all.yaml

apiVersion: v1
kind: Service
metadata:
  name: http-all
  namespace: opx
spec:
  type: NodePort
  selector:
    app: web      <<<----通过app标签匹配v1-v2容器
  ports:
  - name: http
    port: 80
    targetPort: 80
    protocol: TCP
    nodePort: 30099     <<<------nodePort可以不用,如使用便是轮询负载

最后VirtualService 负责权重 DestinationRule负责细分

cat <<END>vs+dr-88.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: test-vir
  namespace: opx
spec:
  hosts:
  - "*"
  gateways:
     - out-api-gateway
  http:
  - route:
    - destination:
        host: http-all
        subset: v1
      weight: 90
    - destination:
        host: http-all
        subset: v2
      weight: 10
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: test-dr
  namespace: opx
spec:
  host: http-all
  trafficPolicy:
    loadBalancer:
      simple: RANDOM
  subsets:
  - name: v1
    labels:
      server: http-v1      <<----通过标签容器匹配
  - name: v2
    labels:
      server: http-v2   <<----通过标签容器匹配
END

在这里插入图片描述

[root@ceph194 ~]# while sleep 1; do  curl 10.98.2.62:5732; done
v1111111111111111111
v1111111111111111111
v22222222222222
v1111111111111111111
v1111111111111111111
v1111111111111111111

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值