ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

istio Egress Gateway 统一流量出口

2022-01-19 18:32:40  阅读:284  来源: 互联网

标签:name istio number egressgateway Egress test com Gateway


1、下载istioctl

https://github.com/istio/istio/releases/download/1.9.0/istioctl-1.9.0-linux-amd64.tar.gz

2、安装istio

istioctl install --set profile=demo --set values.global.hub=192.168.2.88:5000/istio -y

3、注入sdicar到名称空间

kubectl label namespace default istio-injection=enabled

4、部署测试程序test.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: greenhouse
  labels:
    app: greenhouse
spec:
  spec:
  replicas: 2
  selector:
    matchLabels:
      app: greenhouse
  template:
    metadata:
      labels:
        app: greenhouse
    spec:
      containers:
      - name: maven
        image: ibmcom/curl:3.6
        args:
        - /bin/sh
        - -c
        - sleep 300000

5、查看注入是否成功(如果pod中有两个容器就绪,代表注入成功)

kubectl get pods

    greenhouse-6c79488485-zjkzw 2/2 Running 0 141m

6、egress gateway需要对外服务为域名,我这里再coreDns加入记录(应该还要其他实现方式)

kubectl edit configmap coredns -n kube-system

  添加hosts字段

  

7、定义 Egress gateway 并引导 HTTP 流量

  首先创建一个 ServiceEntry,允许流量直接访问一个外部服务,为 test.com 定义一个 ServiceEntry

kubectl apply -f ServiceEntry.yaml

apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: cnn
spec:
  hosts:
  - test.com
  ports:
  - number: 8080
    name: http-port
    protocol: HTTP
  - number: 443
    name: https
    protocol: HTTPS
  - number: 80
    name: http-port1
    protocol: HTTP
  - number: 8088
    name: http-port2
    protocol: HTTP
  resolution: DNS

   为 test.com 端口 80 创建 egress Gateway。并为指向 egress gateway 的流量创建一个 destination rule。

kubectl apply -f gateway.yaml

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: istio-egressgateway
spec:
  selector:
    istio: egressgateway
  servers:
  - port:
      number: 8080
      name: http
      protocol: HTTP
    hosts:
    - test.com
  - port:
      number: 80
      name: http1
      protocol: HTTP
    hosts:
    - test.com
  - port:
      number: 8088
      name: http2
      protocol: HTTP
    hosts:
    - test.com
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: egressgateway-for-cnn
spec:
  host: istio-egressgateway.istio-system.svc.cluster.local
  subsets:
  - name: cnn

  定义一个 VirtualService,将流量从 sidecar 引导至 egress gateway,再从 egress gateway 引导至外部服务

kubectl apply -f vs.yaml

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: direct-cnn-through-egress-gateway1
spec:
  hosts:
  - test.com
  gateways:
  - istio-egressgateway
  - mesh
  http:
  - match:
    - gateways:
      - mesh
      port: 80
    route:
    - destination:
        host: istio-egressgateway.istio-system.svc.cluster.local
        subset: cnn
        port:
          number: 80
      weight: 100
  - match:
    - gateways:
      - istio-egressgateway
      port: 80
    route:
    - destination:
        host: test.com
        port:
          number: 80
      weight: 100

  测试是否配置成功

    在测试容器中像外部程序发起访问

 kubectl  exec -it greenhouse-6c79488485-zjkzw sh
   curl -i http://test.com

  查看egress容器日志,发现有访问日志

kubectl  logs istio-egressgateway-56f74c7d66-ngm8j   -n istio-system  -f

 

   至此 egress gateway配置完成,还有不少疑问有待找寻答案。

   来日再叙。。。。。。。。。。

  

标签:name,istio,number,egressgateway,Egress,test,com,Gateway
来源: https://www.cnblogs.com/sandiandian/p/15823581.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有