0
点赞
收藏
分享

微信扫一扫

k8s如何使用service和endpoint转发外部服务?

书坊尚 2021-09-28 阅读 43

并不是service暴露一个外部ip,而是service转发外部ip+port,做法如下:

首先,创建endpoint:

apiVersion: v1
kind: Endpoints
metadata:
  name: http
  namespace: default
subsets:
- addresses:
  - ip: 10.2.1.1
  ports:
  - name: http
    port: 8080
    protocol: TCP

其中10.2.1.1:8080是外部服务。

其次,创建service,其中名字一定要和endpoint的一致:

apiVersion: v1
kind: Service
metadata:
  name: http
  namespace: default
spec:
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80

然后访问service自动生成的虚拟ip加port即可。

举报

相关推荐

0 条评论