1. ---
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. name: cluster-link
  6. namespace: hivesec
  7. spec:
  8. type: ClusterIP
  9. selector: #标签选择器
  10. app: cluster-link
  11. ports:
  12. - name: cluster-link #端口名称(唯一)
  13. port: 9001 #service端口
  14. targetPort: 9001 #容器端口
  15. protocol: TCP #端口协议
  16. - name: proxy
  17. port: 1080
  18. targetPort: 1080
  19. protocol: TCP

Service

ClusterIP:集群内部访问,如果是NodePort,就是暴露端口到集群外部。

service访问过程:
image.png

port是service的的端口
targetport是pod也就是容器的端口
nodeport是容器所在宿主机的端口(实质上也是通过service暴露给了宿主机,而port却没有)