gateway-service.yaml 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: shop-recycle-gateway
  5. namespace: default
  6. labels:
  7. app: shop-recycle-gateway
  8. service: gateway
  9. annotations:
  10. description: "Shop Recycle Gateway Service"
  11. spec:
  12. # 服务类型
  13. type: ClusterIP # 改为 LoadBalancer 以实现外部访问
  14. # IP 亲和性
  15. sessionAffinity: ClientIP
  16. sessionAffinityConfig:
  17. clientIP:
  18. timeoutSeconds: 10800
  19. # 选择器
  20. selector:
  21. app: shop-recycle-gateway
  22. # 端口映射
  23. ports:
  24. # HTTP 端口
  25. - name: http
  26. port: 1211 # Service 端口(集群内访问)
  27. targetPort: 1211 # Pod 端口
  28. protocol: TCP
  29. nodePort: 31211 # 仅在 NodePort 或 LoadBalancer 类型时使用
  30. # Sentinel 监控端口(可选)
  31. - name: sentinel
  32. port: 8005
  33. targetPort: 8005
  34. protocol: TCP
  35. ---
  36. # 可选:NodePort 类型 Service(用于本地测试)
  37. apiVersion: v1
  38. kind: Service
  39. metadata:
  40. name: shop-recycle-gateway-nodeport
  41. namespace: default
  42. labels:
  43. app: shop-recycle-gateway
  44. service: gateway-nodeport
  45. annotations:
  46. description: "Shop Recycle Gateway NodePort Service for testing"
  47. spec:
  48. type: NodePort
  49. selector:
  50. app: shop-recycle-gateway
  51. ports:
  52. - name: http
  53. port: 1211
  54. targetPort: 1211
  55. nodePort: 31211 # 节点端口,范围 30000-32767
  56. ---
  57. # 可选:Ingress(用于 HTTP 路由)
  58. apiVersion: networking.k8s.io/v1
  59. kind: Ingress
  60. metadata:
  61. name: shop-recycle-gateway-ingress
  62. namespace: default
  63. labels:
  64. app: shop-recycle-gateway
  65. annotations:
  66. cert-manager.io/cluster-issuer: "letsencrypt-prod"
  67. nginx.ingress.kubernetes.io/rewrite-target: /
  68. nginx.ingress.kubernetes.io/rate-limit: "100"
  69. spec:
  70. ingressClassName: nginx # 根据集群中的 ingress controller 修改
  71. rules:
  72. - host: gateway.example.com # 修改为实际域名
  73. http:
  74. paths:
  75. - path: /
  76. pathType: Prefix
  77. backend:
  78. service:
  79. name: shop-recycle-gateway
  80. port:
  81. number: 1211
  82. # TLS 证书配置(可选)
  83. # tls:
  84. # - hosts:
  85. # - gateway.example.com
  86. # secretName: gateway-tls-cert