备考ICA----Istio实验14---出向流量管控Egress Gateways实验

备考ICA----Istio实验14---出向流量管控Egress Gateways实验

1. 发布测试用 pod

bash 复制代码
kubectl apply -f istio/samples/sleep/sleep.yaml
kubectl get pods -l app=sleep

2. ServiceEntry

创建一个ServiceEntry允许流量访问edition.cnn.com

egressgw/edition-ServiceEntry.yaml

yaml 复制代码
apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
  name: cnn
spec:
  hosts:
  - edition.cnn.com
  ports:
  - number: 80
    name: http-port
    protocol: HTTP
  - number: 443
    name: https
    protocol: HTTPS
  resolution: DNS

部署ServiceEntry

bash 复制代码
kubectl apply -f egressgw/edition-ServiceEntry.yaml

访问测试

bash 复制代码
kubectl exec deploy/sleep -- curl -sSL -o /dev/null \
-D - http://edition.cnn.com/politics

检查egress的日志

bash 复制代码
kubectl logs -l istio=egressgateway -c istio-proxy -n istio-system | tail

此时流量是从pod上的envoy直出到公网的.

bash 复制代码
kubectl logs sleep-7656cf8794-xwqww -c istio-proxy  | tail

3.将流量导向egress

3.1 定义出口网关规则

edition.cnn.com 创建一个出口,端口 80,并为定向到出口网关的流量创建一个目标规则

egressgw/cnn-egressgateway.yaml

yaml 复制代码
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: istio-egressgateway
spec:
  selector:
    istio: egressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - edition.cnn.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

部署

bash 复制代码
kubectl apply -f egressgw/cnn-egressgateway.yaml 

3.2 配置egress规则

配置路由规则,将流量从边车导向到 Egress Gateway,再从 Egress Gateway 导向到外部服务

egressgw/direct-cnn-through-egress-gateway.yaml

yaml 复制代码
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: direct-cnn-through-egress-gateway
spec:
  hosts:
  - edition.cnn.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: edition.cnn.com
        port:
          number: 80
      weight: 100

部署

bash 复制代码
kubectl apply -f egressgw/direct-cnn-through-egress-gateway.yaml

3.3 再次测试访问

bash 复制代码
kubectl exec deploy/sleep -- curl -sSL \
-o /dev/null -D - http://edition.cnn.com/politics

看上去和之前一样,再看下sleep的envoy日志,本次的流量也从envoy sidecar上出去了

bash 复制代码
kubectl logs sleep-7656cf8794-xwqww -c istio-proxy  | tail

再看egress的envoy上的日志,之前那次是没有经过egress的,这次流量明显是从egress出去的

bash 复制代码
kubectl logs -l istio=egressgateway -c istio-proxy -n istio-system | tail

我们已经将出向的流量配置成由Egress转发

至此备考ICA----Istio实验14---出向流量管控Egress Gateways实验完成

相关推荐
霸道流氓气质16 小时前
微服务架构中多实例消息抢占问题:技术解析与解决方案
微服务·云原生·架构
AAA@峥18 小时前
K8s 资源管控:ResourceQuota 与 LimitRange 机制详解与实战
云原生·容器·kubernetes
云烟成雨TD20 小时前
Micrometer 系列【63】统一观测:基于 Spring Boot 的生产级演示案例 | 基于 OTLP 集成 Prometheus + Jaeger
spring boot·云原生·prometheus
猫吃了源码21 小时前
CentOS7使用Kubeadm安装部署K8s(Kubernetes)最新稳定版本1.26.x
云原生·容器·kubernetes
张忠琳21 小时前
【k3s】AutoK3s v0.9.3 —— Part 7 辅助模块超深度逐行分析
云原生·容器·kubernetes·k3s·autok3s
张忠琳1 天前
【k3s】AutoK3s v0.9.3 Part 1 入口与 CLI 命令模块 — 超深度逐行分析之三
云原生·容器·kubernetes·k3s·autok3s
m0_525724721 天前
AIOps全链路智能运维架构揭秘
云原生·devops
xiaoxiangsiyan2 天前
企业日常运维高频应用服务全解
运维·网络·云原生·容器·dns
阿里云云原生2 天前
一次请求只做一次决策:阿里云 AI 网关智能路由如何替大模型应用选模型
云原生
zhangjw342 天前
第41篇:微服务入门:架构理念+核心组件,理解微服务本质
微服务·云原生·架构