ingress与gateway https秘钥配置

12 篇文章 4 订阅

腾讯saas流量迁移记录
1 isito中的ingress和gateway
k8s中相关知识的回忆:
集群外部访问Service,可以将type设置为nodePort、ExternalName和externalIPs、LoadBalancer、Ingress
LoadBalancer:
该类型的Service被提交后,Kubernetes 就会调用 CloudProvider 在公有云上为你创建一个负载均衡服务,并且把被代理的 Pod 的 IP 地址配置给负载均衡服务做后端。
kuebctl get svc :可以看到external-ip。我们就可以通过该ip+port来访问了。

Ingress:
由于每个LoadBalancer类别的Service 都要有一个负载均衡服务,所以这个做法实际上浪费成本,更希望看到 Kubernetes 为我内置一个全局的负载均衡器。然后,通过我访问的 URL,把请求转发给不同的后端 Service。
对应的就是Kubernetes 里的 Ingress 服务。
ingress对象的定义如下:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: cafe-ingress
spec:
  tls:
  - hosts:
    - cafe.example.com
    secretName: cafe-secret
  rules:
  - host: cafe.example.com
    http:
      paths:
      - path: /tea
        backend:
          serviceName: tea-svc
          servicePort: 80
      - path: /coffee
        backend:
          serviceName: coffee-svc
          servicePort: 80
重点关注rules字段。
host:该Ingress对象的入口,即当用户访问 cafe.example.com 的时候,实际上访问到的是这个Ingress对象。
对应的值必须是一个标准的域名格式的字符串,而不能是 IP 地址。

引入istio之后
统一域名rest.xiaohoucode.com,对应到公网ip1
服务网格asm ingressgateway绑定了上面的ip1,所以请求会进入istio

先了解阿里云istio中的ingress
istio中kind为:IstioGateway,绑定的集群是k8s的istio-ingressgateway对应的集群
下面是k8s中istio-ingressgateway的service集群 type是LoadBalancer类型,selector是app: istio-ingressgateway
再下面是k8s中的istio-ingressgateway,实际的pod。

istio中的gateway:
说明:gateway中的selector对应的也是istio: ingressgateway,最终也会影视到上面istio-ingressgateway的pod
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: abtest-gateway
  namespace: peiyou-****
spec:
  selector:
    istio: ingressgateway
  servers:
    - hosts:
        - '*'
      port:
        name: http
        number: 80
        protocol: HTTP
    - hosts:
        - '*'
      port:
        name: https
        number: 443
        protocol: HTTPS
      tls:
        credentialName: istio-ingressgateway-certs
        mode: SIMPLE
所以:isito的ingress和gateway对应的pod是一样的,所以ingress对应的pod的功能主要就是从公网接收请求转到isito内部的gateway
然后vs再引用gateway,gateway将请求分发到不同的vs,vs层再将请求分发到k8s的service,最后到具体的pod

和gateway istio

怎么理解ingress和gateway的作用
ingress一般是对应一个公网ip,负责从外部接收流量
gateway是接收外部的请求,并根据配置规则分配给内部的service
相关pod是干活的

2 怎么通过https的方式发布无服务网格内的服务
两种方式:
1 tls相关文件上传,引用方式如下:
如下:
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: abtest-gateway-saas
  namespace: peiyou-xiaohoucode-saas
spec:
  selector:
    istio: ingressgateway
  servers:
    - hosts:
        - '*'
      port:
        name: http
        number: 80
        protocol: HTTP
    - hosts:
        - '*'
      port:
        name: https
        number: 443
        protocol: HTTPS
      tls:
        mode: SIMPLE
        privateKey: /etc/istio/ingressgateway-certs/tls.key
        serverCertificate: /etc/istio/ingressgateway-certs/tls.crt
2 获取tls相关配置后建立secrets,将相关内容存储在secrets,
secretc配置:
apiVersion: v1
data:
  tls.crt: LS0tCg==
  tls.key: LS0tg==
kind: Secret
metadata:
  creationTimestamp: "2022-10-19T03:41:01Z"
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:data:
        .: {}
        f:tls.crt: {}
        f:tls.key: {}
      f:type: {}
    manager: rancher
    operation: Update
    time: "2022-10-19T03:41:01Z"
  name: istio-ingressgateway-certs
  namespace: istio-system
  resourceVersion: "49154055"
  selfLink: /api/v1/namespaces/istio-system/secrets/istio-ingressgateway-certs
  uid: c172c8b5-b1c5-4edb-85b3-c7e08a34cea5
type: kubernetes.io/tls

gateway中的引用:
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: abtest-gateway
  namespace: peiyou-xiaohoucode
spec:
  selector:
    istio: ingressgateway
  servers:
    - hosts:
        - '*'
      port:
        name: http
        number: 80
        protocol: HTTP
    - hosts:
        - '*'
      port:
        name: https
        number: 443
        protocol: HTTPS
      tls:
        credentialName: istio-ingressgateway-certs #这里是secret的名称
        mode: SIMPLE

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值