istio1.8网关暴露

在这里插入图片描述

demon下

https://gitee.com/jbjb123/istio-demon.git
自动注入
kubectl label namespace opx istio-injection=enabled
取消
istio-injection=disabled 

暴露网关out-api.yaml

tee out-api.yaml <<-'EOF'
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:
    - "*"
EOF

查看一下网关暴露的ip

[root@master-63 test]# kubectl get svc -n istio-system istio-ingressgateway
NAME                   TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                                     AGE
istio-ingressgateway   LoadBalancer   10.106.170.129   <pending>     15020:25264/TCP,80:5732/TCP,443:42105/TCP,31400:53129/TCP,15443:18269/TCP   16d

在这里插入图片描述
准备V1版本

tee v1.yaml <<-'EOF'
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
---
apiVersion: v1
kind: Service
metadata:
  name: http-v1
  namespace: opx
spec:
  type: NodePort
  selector:
    server: http-v1
  ports:
  - name: http
    port: 80
    targetPort: 80
    protocol: TCP
    nodePort: 30090
EOF

准备V2版本

tee v2.yaml <<-'EOF'
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

---

apiVersion: v1
kind: Service
metadata:
  name: http-v2
  namespace: opx
spec:
  type: NodePort
  selector:
    server: http-v2
  ports:
  - name: http
    port: 80
    targetPort: 80
    protocol: TCP
    nodePort: 30092
EOF

最后VirtualService添加权重

tee gat.yaml <<-'EOF'
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: api-gateway-ha
  namespace: opx
spec:
  hosts:
  - "*"
  gateways:
     - out-api-gateway
  http:
  - route:
    - destination:
        host: http-v1
        #subset: v1
      weight: 90
    - destination:
        host: http-v2
        #subset: v2
      weight: 10
EOF

打入流量测试是否生效

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

在这里插入图片描述
查看virtualservice 和 gateway

[root@master-63 test]# kubectl get gateway -n opx
NAME              AGE
out-api-gateway   66m
[root@master-63 test]# kubectl get virtualservice -n opx
NAME             GATEWAYS            HOSTS   AGE
api-gateway-ha   [out-api-gateway]   [*]     53m
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值