备考ICA----Istio实验11---为多个主机配置TLS Istio Ingress Gateway实验

备考ICA----Istio实验11---为多个主机配置TLS Istio Ingress Gateway实验

1. 部署应用

bash 复制代码
kubectl apply -f istio/samples/helloworld/helloworld.yaml -l service=helloworld
kubectl apply -f istio/samples/helloworld/helloworld.yaml -l version=v1

2. 证书准备

接上一个实验,准备第二个证书

bash 复制代码
openssl req -out example_certs_pana/pana.example.com.csr  -newkey rsa:2048 \
-nodes -keyout example_certs_pana/pana.example.com.key \
-subj "/CN=pana.example.com/O=httpbin organization"

签发证书

bash 复制代码
openssl x509 -req -sha256 -days 365 -CA example_certs_root/example.com.crt \
-CAkey example_certs_root/example.com.key \
-set_serial 0 -in example_certs_pana/pana.example.com.csr \
-out example_certs_pana/pana.example.com.crt

将证书生成secret

因为后续也是使用istio/ingressgateway所以必须放着istio-system命名空间下

bash 复制代码
kubectl create secret -n istio-system tls  pana-credential \
--key=example_certs_pana/pana.example.com.key \
--cert=example_certs_pana/pana.example.com.crt

确认secret被正确创建

bash 复制代码
kubectl get secrets -n istio-system 

3. Istio配置

3.1 Gateway配置

这里新的hello服务和上个实验合用mygateway这个gateway对外提供访问,但各自使用各自的TLS证书.

tls-ingress/2-TLS-gateway.yaml

yaml 复制代码
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: mygateway
spec:
  selector:
    istio: ingressgateway                       # use istio default ingress gateway
  servers:
  - port:
      number: 443
      name: httpbin
      protocol: HTTPS
    tls:
      mode: SIMPLE
      credentialName: httpbin-credential        # must be the same as secret
    hosts:
    - httpbin.example.com
  - port:
      number: 443
      name: pana
      protocol: HTTPS
    tls:
      mode: SIMPLE
      credentialName: pana-credential   # must be the same as secret
    hosts:
    - pana.example.com

3.2 VirtualService配置

在vs中定义了监听mygateway的hosts是pana.example.com,匹配上uri:/hello后转发给svc helloworld的后端进行响应.

tls-ingress/2-TLS-VirtualService.yaml

yaml 复制代码
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: pana
spec:
  hosts:
  - "pana.example.com"
  gateways:
  - mygateway
  http:
  - match:
    - uri:
        prefix: /hello
    route:
    - destination:
        port:
          number: 5000
        host: helloworld

可以看到2个服务使用了同一个gw,但各自又有自己的Vs

4. 访问测试

4.1 pana.example.com

linux下

bash 复制代码
curl -v -HHost:pana.example.com --resolve "pana.example.com:443:192.168.126.220" \
 --cacert example_certs_root/example.com.crt "https://pana.example.com:443/hello"

4.2 httpbin.example.com

上一个实验部署的httpbin.example.com

linux下

bash 复制代码
curl -v -HHost:httpbin.example.com --resolve \
"httpbin.example.com:443:192.168.126.220" \
--cacert example_certs_root/example.com.crt \
"https://httpbin.example.com:443/status/418"

至此为多个主机配置TLS Istio Ingress Gateway实验完成

相关推荐
容器魔方10 小时前
Volcano v1.12 正式发布!驱动云原生AI与批量计算向智能高效新阶段演进
云原生·容器·云计算
在未来等你13 小时前
互联网大厂Java求职面试:云原生架构与微服务设计中的复杂挑战
java·微服务·ai·云原生·秒杀系统·rag·分布式系统
jarenyVO14 小时前
Spring Cloud Gateway 全面学习指南
java·gateway
fdsafwagdagadg657619 小时前
本地部署n8n和MoneyPrintTuro实现一句话自动生成和上传youtube短视频
云原生·eureka
掘金-我是哪吒1 天前
分布式微服务系统架构第145集:Jeskson文档-微服务分布式系统架构
分布式·微服务·云原生·架构·系统架构
国际云,接待1 天前
微软云注册被阻止怎么解决?
服务器·网络·microsoft·云原生·微软·云计算
老实巴交的麻匪1 天前
可观测性 | Grafana Loki 日志聚合方案快速体验
运维·云原生·容器
炎码工坊2 天前
DevSecOps实践:CI/CD流水线集成动态安全测试(DAST)工具
安全·网络安全·微服务·云原生·安全架构
Akamai中国2 天前
为何AI推理正推动云计算从集中式向分布式转型
人工智能·云原生·云计算·边缘计算
程序员阿超的博客2 天前
云原生核心技术 (9/12): K8s 实战:如何管理应用的配置 (ConfigMap/Secret) 与数据 (Volume)?
云原生·容器·kubernetes