《Istio in Action》笔记1
  YKMEHzdP8aoh 2023年11月02日 37 0

摘要:

Gateway;VirtualService;istioctl;


1、Gateway资源配置Envoy监听80端口并等待HTTP流量。Route:由一个Service的Listener进入的所有流量(match /*)全部路由给该Service的各Pod生成的Cluster。

  • 网关资源定义了希望在服务网格集群边缘侦听的端口、协议和虚拟主机。VirtualService资源定义了流量在边缘被允许进入后应该去哪里
  • 网关定义是针对istio-ingressgateway的,它是最初设置istio时创建的,使用网关配置的选择器部分中的标签来定义配置应用于哪个网关,选择标签为istio:ingressgateway的网关实现,istio-ingressgateway的Gateway是istio服务代理(Envoy)的一个实例。istio-ingressgateway侦听集群外部暴露的端口或IP。例如本地k8s环境(没有LoadBalancer),入口网关监听NodePort。NodePort使用Kubernetes集群的一个节点上的真实端口。
  • 使用VirtualService资源,将流量从入口网关(Gateway监听IP:NodePort;监听端口:80)路由routes到特定的服务webapp。
  • Istio对比K8s Ingress:Ingress规范只将80端口和443端口视为入口点,不支持TCP连接。Istio的Gateway处理第4层和第5层的问题,而VirtualService处理第7层的问题
->External Client --> IngressGateway Service --> IngressGateway Pod(Listener(由Gateway定义) --> Route(由VirtualService定义)--> Cluster(可由控制平面通过发现的的Service自动配置) --> endpoint )
# istioctl -n istio-system proxy-config listener deploy/istio-ingressgateway
ADDRESS PORT  MATCH DESTINATION
0.0.0.0 8080  ALL   Route: http.8080
0.0.0.0 15021 ALL   Inline Route: /healthz/ready*
0.0.0.0 15090 ALL   Inline Route: /stats/prometheus*
# istioctl -n istio-system proxy-config  route deploy/istio-ingressgateway -o json --name http.8080
                "name": "hiroakis.com:80",
                "domains": [
                    "hiroakis.com"
                ],
                "routes": [
                    {
                        "match": {
                            "prefix": "/"
                        },
                        "route": {
                            "cluster": "outbound|80||webapp.bookinfo.svc.cluster.local",
->Client --> Envoy Sidecar (outbound:egress listener --> route --> cluster --> endpoint (由目标生生成)) --> Server Pod Envoy Sidecar (inbound: ingress listener --> route --> local cluster --> localhost(业务容器)(自由所属的服务生成))

2、VirtualService定义规则适用于来自- bookinfo-gateway网关的流量,指定了虚拟主机hosts:  - "hiroakis.com" ,匹配hiroakis.com规则,将其解析为Istio网关正在监听的IP地址(NodePort)。

  • VirtualService在Istio网关中创建一个Envoy路由,将流量匹配域hiroakis.com路由到服务网格中的webapp。测试:客户端显示地将HTTP请求中的Host头设置为hiroakis.com,即在命令中覆盖Host头
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: webapp-virtualservice
spec:
  hosts:
  - "hiroakis.com"  
  gateways:
  - bookinfo-gateway
  http:
  - route: 
    - destination: 
        host: webapp
        port:
          number: 80
ok---># curl http://hiroakis.com:30933/api/catalog -H "Host: hiroakis.com"   
ok---># curl http://10.16.96.141/api/catalog -H "Host: hiroakis.com"
nok--># curl http://10.16.96.141/api/catalog

3、istioctlexperimental 子命令查看一个pod是否在网格中,以及检查该pod的配置,也可以展示流量权重。输出显示50%的catalog服务的流量导入到了v1 subset中http://www.manongjc.com/detail/56-rcocgckekmloloy.html)(https://istio.io/latest/docs/reference/commands/istioctl/#istioctl-experimental-describe-pod)(https://istio.io/v1.15/zh/docs/ops/diagnostic-tools/istioctl-describe/

# istioctl -n bookinfo x describe pod catalog-699669c844-gjscb   //和其它istioctl命令一样,可以用x来代替experimental
# istioctl experimental -n bookinfo describe pod catalog-699669c844-gjscb
Pod: catalog-699669c844-gjscb
   Pod Revision: default
   Pod Ports: 3000 (catalog), 15090 (istio-proxy)
--------------------
Service: catalog
   Port: http 80/HTTP targets pod port 3000
DestinationRule: catalog for "catalog"
   Matching subsets: version-v1
      (Non-matching subsets version-v2)
   No Traffic Policy
--------------------
Effective PeerAuthentication:
   Workload mTLS mode: PERMISSIVE
Exposed on Ingress Gateway http://192.168.31.216
VirtualService: catalog
   Weight 50%
# istioctl experimental -n bookinfo describe svc catalog
Service: catalog
   Port: http 80/HTTP targets pod port 3000
DestinationRule: catalog for "catalog"
   Matching subsets: version-v1,version-v2
   No Traffic Policy
Exposed on Ingress Gateway http://192.168.31.216
VirtualService: catalog
   Weight 50%
   Weight 50%

4、保护网关流量,在Istio网关上设置TLS,任何进入的流量都通过HTTPS。

  • 入口流量启用HTTPS,需要指定网关应该私用的正确的私钥和证书webapp-credential。
  • 网关中用于TLS的秘钥webapp-credential只能在与Istio入口网关相同的命名空间istio-system中检索。
# k -n istio-system create secret tls webapp-credential --key certs/3_application/private/webapp.istioinaction.io.key.pem --cert certs/3_application/certs/webapp.istioinaction.io.cert.pem 
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: coolstore-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 443
      name: https
      protocol: HTTPS
    tls:
      mode: SIMPLE
      credentialName: webapp-credential
    hosts:
    - "webapp.istioinaction.io"
-->istio-ingressgateway   LoadBalancer   10.16.96.141  443:30815/TCP
  • curl验证:指定Host头;指定CA证书链--cacert传递给curl客户端;使用参数--resolve标志将证书中的主机名和端口(webapp.istioinaction.io:30815)映射到正在使用的真实IP地址(192.168.31.220)。
# curl -H "host:webapp.istioinaction.io" https://webapp.istioinaction.io:30815/api/catalog --cacert certs/2_intermediate/certs/ca-chain.cert.pem --resolve webapp.istioinaction.io:30815:192.168.31.218
--->/etc/hosts---未配置域名:192.168.31.220  192.168.31.220--->--resolve webapp.istioinaction.io:30815:192.168.31.220
# curl -v -H "host:webapp.istioinaction.io" https://webapp.istioinaction.io:30815/api/catalog --cacert certs/2_intermediate/certs/ca-chain.cert.pem --resolve webapp.istioinaction.io:30815:192.168.31.220
  • Windows主机浏览器输入https://webapp.istioinaction.io:30815/提示“你的连接不是专用连接 攻-击者可能试图从 webapp.istioinaction.io 窃取你的信息(例如,密码、消息或信用卡)。NET::ERR_CERT_AUTHORITY_INVALID”
  • 点击:继续访问 webapp.istioinaction.io (不安全),访问正常。
C:\Windows\System32\drivers\etc\hosts
192.168.31.218  webapp.istioinaction.io
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  38gcbVXUBcLA   2023年11月26日   22   0   0 服务器htmlHTTP
  ozzp9aSSE46S   2023年11月30日   26   0   0 DNSIPPod
  YKMEHzdP8aoh   2023年12月11日   57   0   0 DNSidePod
  eHipUjOuzYYH   2023年12月06日   26   0   0 nginxHTTP
  38gcbVXUBcLA   2023年11月25日   23   0   0 服务器客户端HTTP