使用 lego 创建 https 证书 https://go-acme.github.io/lego/dns/ 1 2 3 4 5 6 7 8 9 10 11 #!/bin/bash # cd $(dirname $0) source .env lego --email="${EMAIL}" \ --key-type rsa2048 \ --domains="${DOMAIN1}" \ --path=$(pwd) --dns $DNS_PROVIDER --accept-tos run……
阅读全文
VirtualService 路由重定向 在 VirtualService 配置中, 除了 http rewrite 路由重写之外, 还有 http redirect 路由重定向。 即常说的 30x。 https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRedirect http redirect VirtualService 重定向配置如下。 有三个重要参数 uri: 重定向后的 uri redirectCode: 重定向时的 http response code。 ex: 301, 302。 默认值为 301 。 authority: 重定向后的 http host。 即 http response header 中的 location 字段。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 --- apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata:……
阅读全文
VirtualService 重试机制 在 Istio VirtualService 中, 有一个很关键的机制: 重试。 发起重试不需要业务本身实现, 而是 istio 通过 envoy 发起的。 其中有几个关键参数 attempts: 重试次数(不含初始请求), 即最大请求次数为 n+1。 perTryTimeout: 发起重试的间隔时间。 必须大于 1ms。 默认于 http route 中的 timeout 一致, 即无 timeout 时间 retryOn: 执行重试的触发条件。 条件值有 envoy 提供: https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/router_filter#x-envoy-retry-on http retry 1……
阅读全文
VirtualService 混沌测试/错误注入 在 Istio 中还实现了一个很重要的功能: 错误注入。 可以设置 一定几率 出现 延迟(delay) 和 中止(abort) 错误。 Http Fault Injection Delay 延迟 一定概率出现 缓慢 相应。 fixedDelay: 延迟时间。 格式 1h / 1m / 1s。 最小 1ms。 percentage: 错误触发几率。 0-100 之间。 可以为 double 类型的小数。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17……
阅读全文
VirtualService 服务委托 服务委托就是流量转发。 https://istio.io/latest/docs/reference/config/networking/virtual-service/#Delegate 如下 VirtualService 的 流量委托 定义, 是在 myistio 这个命名空间中创建的。 但是将 myistio.tangx.in/prod 的流量转发到了命名空间 myistio-prod 中的 prod 服务中; 同样将 myistio.tangx.in/reviews 的流量转发到了命名空间 myistio-review 中的 review 服务中。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 # vs http delegate apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: vs-delegate namespace: myistio # 注意 namespace spec: gateways: - istio-tangx-in hosts: - istio.tangx.in http: - match: -……
阅读全文
VirtualService Header 操作 当 Envoy 在进行请求流量转发的时候, 还可以对消息 (request/response) 的 Header 进行操作。 set : 如果不存在, 则 创建 header, 如果存在, 则 覆盖 header 1 2 3 4 5 6 7 spec: http: - headers: request: set: key1: value1 key2: value2 add : 如果不存在, 则 新增; 如果村子啊, 则 追加 1 2 3 4 5 6 7 spec: http: - headers: request: add: key1: value1 key2: value2 remove: 如果存在, 则 删除 header; 不存在, 则 忽略 1 2 3 4 5 6 7 spec:……
阅读全文
Gateway 支持 https 访问 - 标准模式 https://istio.io/latest/docs/reference/config/networking/gateway/#ServerTLSSettings credentialName: The secret (of type generic) should contain the following keys and values: key: <privateKey> and cert: <serverCert> 创建证书 k8s secret 在 标准模式 下, 必须使用 key 作为私钥文件名, cert 作为证书文件名。 证书文件需要 保持 与 istio-ingressgateway 服务在 相同 的命名空间。 因此证书文件的创建命令如下 1 2 3 4 kubectl create secret generic wild-tangx-in \ --from-file=key=./certificates/_.tangx.in.key \ --from-file=cert=./certificates/_.tangx.in.crt \ -n istio-system 其中 wild-tangx-in: 是 secret name。 之后 istio gateway 需要使用 ./certificates/_.tangx.in.key(crt) 是证书私钥/……
阅读全文
使用 DestionationRule 流量控制策略 - 简单负载均衡 简单负载均衡 策略, 官方指定名称。 ROUND_ROBIN: 轮训策略, 默认。 LEAST_CONN: 最小连接数。 随机 选择 两个健康 后端, 通过 O(1) 算法选择连接数最少的后端。 RANDOM: 随机选择了一个 健康 后端。 如果 没有配置健康检查策略, 随机策略比轮训更好。 PASSTHROUGH: 此选项会将连接转发到调用者请求的原始 IP 地址,而不进行任何……
阅读全文
isti VirtualService 和 k8s Ingress 可以简单的认为 Ingress 是 k8s 中提出的流量入口转发的一个 标准定义规范(只是认为)。 怎么实现, 需要根据不同的 IngressController 的逻辑。 VirtualService 的部分功能就承担了 Ingress 的这一功能。 1. Ingress 与 VirtualService 的定义 k8s Ingress 配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 apiVersion: networking.k8s.io/v1 kind: Ingress metadata: creationTimestamp: null name: simple spec: rules: - host: foo.com # 访问的域名 http: paths: - backend: service: name: svc1 # 后端服务名称 port: number: 80……
阅读全文
使用 istio Gateway 允许外部访问 仅仅是简单的创建了 VirtualService 是不能实现集群外部的访问的。 在 Istio 中, 还有一个 Gateway 的概念。 顾名思义, Gateway 就是大门保安, 只允许具有特定特征的流量通过。 1.1. 创建 Gateway 先来创建一个 Gateway 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 --- # https://istio.io/latest/docs/reference/config/networking/gateway/ apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: istio-tangx-in namespace: myistio spec: selector: istio: ingressgateway # 选择 ingressgateway, 省略则兼容所有 servers: - port: number: 80 name: http protocol:……
阅读全文