istio ServiceEntry使用例子

说明

ServiceEntry和kubernetes service的功能是一样的,不同的地方是ServiceEntry指向外部地址或者其他kubernetes service或者endpoint

话不多说,现在结合VirtualService给出个Demo
VirtualService yaml文件

kind: VirtualService
metadata:
  name: ssdemo
  namespace: demo
spec:
  gateways:
  - kubeflow/kubeflow-gateway # 网关
  hosts:
  - '*'
  http:
  - match:
    - uri:
        prefix: /tensorboard/qinzhao/ssdemo/
    rewrite:
      uri: /
    route:
    - destination:
        host: mymongodb.somedomain ## ServiceEntry指定的域名
        port:
          number: 6006 # 外部端口
    timeout: 300s

ServiceEntry yaml

apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: external-svc-mongocluster
  namespace: qinzhao
spec:
  hosts:
  - mymongodb.somedomain # 服务网格内地址
  ports:
  - number: 6006 # 外部协议端口
    name: http 
    protocol: http  # 外部协议名称
  location: MESH_EXTERNAL # 表明是服务网格之外的
  resolution: STATIC
  endpoints:
  - address: 192.168.1.10 # 外部服务地址

需要注意的是 VirtualService和ServiceEntry中的 mymongodb.somedomain 需要保持一致


WorkloadEntry使用例子

WorkloadEntry就是可以通过ServiceEntry选择的实例,对应kubernetes节点上的Pod实例

kind: WorkloadEntry
metadata:
  name: details-vm-2
  namespace: qinzhao
spec:
  address: 192.168.1.10 # 外部地址
  ports:
    number: 6006
  labels:
    app: details-legacy
    instance-id: vm1

ServiceEntry

kind: ServiceEntry
metadata:
  name: details-svc
  namespace: qinzhao
spec:
  hosts:
  - details.bookinfo.com
  location: MESH_INTERNAL
  ports:
  - number: 80
    name: http
    protocol: HTTP
    targetPort: 6006
  resolution: DNS
  workloadSelector:
    labels:
      app: details-legacy

VirtualService

kind: VirtualService
metadata:
  name: ssdemo
  namespace: qinzhao
spec:
  gateways:
  - kubeflow/kubeflow-gateway
  hosts:
  - '*'
  http:
  - match:
    - uri:
        prefix: /tensorboard/qinzhao/ssdemo/
    rewrite:
      uri: /
    route:
    - destination:
        host: details.bookinfo.com # 对应上 ServiceEntry hosts的字段
        port:
          number: 80
    timeout: 300s
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值