重定向到外部 ip 和 port.

5.2.1 介绍服务 endpoint

service 并不和 pod 直接相连, 中间是 endpoint.

image.png

  1. $ kubectl describe svc hello-svc
  2. Name: hello-svc
  3. Namespace: default
  4. Labels: <none>
  5. Annotations: <none>
  6. Selector: app2=svc
  7. Type: ClusterIP
  8. IP Families: <none>
  9. IP: 10.100.55.166
  10. IPs: 10.100.55.166
  11. Port: <unset> 80/TCP
  12. TargetPort: 8080/TCP
  13. Endpoints: 172.17.0.6:8080,172.17.0.7:8080,172.17.0.8:8080
  14. Session Affinity: None
  15. Events: <none>

Endpoint 资源就是暴露一个服务的 IP 和端口的列表.

  1. $ kubectl get endpoints hello-svc
  2. NAME ENDPOINTS AGE
  3. hello-svc 172.17.0.6:8080,172.17.0.7:8080,172.17.0.8:8080 77m

5.2.2 手动配置服务的 endpoint

service 使用 endpoint 来知道有那些 pod.

创建没有选择器的服务

image.png

  • 也没有 targetPort

为没有选择器的服务创建 Endpoint 资源

image.png

image.png

最初介绍创建 service 的方法使用了标签选择器, 但是外部 server 不在集群中, 所以选不了, 这时需要手动创建关系.

5.2.3 为外部服务创建别名

创建 ExternalName 类型的服务

像是重命名, CNAME

image.png

创建完成后使用 external-service 访问服务.