| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- apiVersion: v1
- kind: Service
- metadata:
- name: shop-recycle-gateway
- namespace: default
- labels:
- app: shop-recycle-gateway
- service: gateway
- annotations:
- description: "Shop Recycle Gateway Service"
- spec:
- # 服务类型
- type: ClusterIP # 改为 LoadBalancer 以实现外部访问
-
- # IP 亲和性
- sessionAffinity: ClientIP
- sessionAffinityConfig:
- clientIP:
- timeoutSeconds: 10800
-
- # 选择器
- selector:
- app: shop-recycle-gateway
-
- # 端口映射
- ports:
- # HTTP 端口
- - name: http
- port: 1211 # Service 端口(集群内访问)
- targetPort: 1211 # Pod 端口
- protocol: TCP
- nodePort: 31211 # 仅在 NodePort 或 LoadBalancer 类型时使用
-
- # Sentinel 监控端口(可选)
- - name: sentinel
- port: 8005
- targetPort: 8005
- protocol: TCP
- ---
- # 可选:NodePort 类型 Service(用于本地测试)
- apiVersion: v1
- kind: Service
- metadata:
- name: shop-recycle-gateway-nodeport
- namespace: default
- labels:
- app: shop-recycle-gateway
- service: gateway-nodeport
- annotations:
- description: "Shop Recycle Gateway NodePort Service for testing"
- spec:
- type: NodePort
- selector:
- app: shop-recycle-gateway
- ports:
- - name: http
- port: 1211
- targetPort: 1211
- nodePort: 31211 # 节点端口,范围 30000-32767
- ---
- # 可选:Ingress(用于 HTTP 路由)
- apiVersion: networking.k8s.io/v1
- kind: Ingress
- metadata:
- name: shop-recycle-gateway-ingress
- namespace: default
- labels:
- app: shop-recycle-gateway
- annotations:
- cert-manager.io/cluster-issuer: "letsencrypt-prod"
- nginx.ingress.kubernetes.io/rewrite-target: /
- nginx.ingress.kubernetes.io/rate-limit: "100"
- spec:
- ingressClassName: nginx # 根据集群中的 ingress controller 修改
- rules:
- - host: gateway.example.com # 修改为实际域名
- http:
- paths:
- - path: /
- pathType: Prefix
- backend:
- service:
- name: shop-recycle-gateway
- port:
- number: 1211
-
- # TLS 证书配置(可选)
- # tls:
- # - hosts:
- # - gateway.example.com
- # secretName: gateway-tls-cert
|