Jelajahi Sumber

Add Headless Service support for Dubbo RPC communication

DevOps Team 2 bulan lalu
induk
melakukan
8c472519cd

+ 55 - 0
add_dubbo_ports.py

@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+import yaml
+from pathlib import Path
+
+repo_root = Path("d:/coding-area/devops/deploy/microservice-helm")
+chart_base = repo_root / "charts"
+
+# Dubbo services mapping
+dubbo_services = {
+    'shop-recycle-account': 2030,
+    'shop-recycle-data-statistics': 2028,
+    'shop-recycle-dealdata-service': 2032,
+    'shop-recycle-dispatcher': 2033,
+    'shop-recycle-merchant': 2023,
+    'shop-recycle-msg': 2026,
+    'shop-recycle-order-center': 2022,
+    'shop-recycle-order-search': 2034,
+    'shop-recycle-payment': 2027,
+    'shop-recycle-pis': 2025,
+    'shop-recycle-platform': 2021,
+    'shop-recycle-store': 2024,
+    'shop-recycle-wechat': 2031,
+}
+
+print("为Dubbo服务添加dubbo_port配置...\n")
+
+for service_name, dubbo_port in dubbo_services.items():
+    values_path = chart_base / service_name / "values.yaml"
+    
+    if not values_path.exists():
+        print(f"WARNING: {service_name} values.yaml not found")
+        continue
+    
+    try:
+        with open(values_path, 'r', encoding='utf-8') as f:
+            values = yaml.safe_load(f)
+    except Exception as e:
+        print(f"ERROR reading {service_name}: {e}")
+        continue
+    
+    # Add dubbo_port to service section
+    if 'service' not in values:
+        values['service'] = {}
+    
+    values['service']['dubbo_port'] = dubbo_port
+    
+    # Write back
+    try:
+        with open(values_path, 'w', encoding='utf-8') as f:
+            yaml.dump(values, f, default_flow_style=False, allow_unicode=True, sort_keys=False)
+        print(f"✓ {service_name}: 添加dubbo_port: {dubbo_port}")
+    except Exception as e:
+        print(f"ERROR writing {service_name}: {e}")
+
+print("\n所有Dubbo服务配置完成!")

+ 5 - 0
charts/base/templates/deployment.yaml

@@ -31,6 +31,11 @@ spec:
         - name: http
           containerPort: {{ .Values.service.targetPort }}
           protocol: TCP
+        {{- if .Values.service.dubbo_port }}
+        - name: dubbo
+          containerPort: {{ .Values.service.dubbo_port }}
+          protocol: TCP
+        {{- end }}
         volumeMounts:
         - name: config-volume
           mountPath: /etc/config

+ 20 - 0
charts/base/templates/service.yaml

@@ -13,3 +13,23 @@ spec:
       name: http
   selector:
     app: {{ .Values.app.name }}
+---
+{{- if .Values.service.dubbo_port }}
+# Headless Service for Dubbo RPC
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Values.app.name }}-dubbo
+  labels:
+    app: {{ .Values.app.name }}
+spec:
+  type: ClusterIP
+  clusterIP: None  # Headless Service
+  ports:
+    - port: {{ .Values.service.dubbo_port }}
+      targetPort: dubbo
+      protocol: TCP
+      name: dubbo
+  selector:
+    app: {{ .Values.app.name }}
+{{- end }}

+ 1 - 0
charts/shop-recycle-account/values.yaml

@@ -9,6 +9,7 @@ service:
   type: ClusterIP
   port: 1223
   targetPort: 1223
+  dubbo_port: 2030
 resources:
   requests:
     cpu: 250m

+ 1 - 0
charts/shop-recycle-data-statistics/values.yaml

@@ -9,6 +9,7 @@ service:
   type: ClusterIP
   port: 1220
   targetPort: 1220
+  dubbo_port: 2028
 resources:
   requests:
     cpu: 250m

+ 1 - 0
charts/shop-recycle-dealdata-service/values.yaml

@@ -9,6 +9,7 @@ service:
   type: ClusterIP
   port: 1235
   targetPort: 1235
+  dubbo_port: 2032
 resources:
   requests:
     cpu: 250m

+ 1 - 0
charts/shop-recycle-dispatcher/values.yaml

@@ -9,6 +9,7 @@ service:
   type: ClusterIP
   port: 1236
   targetPort: 1236
+  dubbo_port: 2033
 resources:
   requests:
     cpu: 250m

+ 1 - 0
charts/shop-recycle-merchant/values.yaml

@@ -9,6 +9,7 @@ service:
   type: ClusterIP
   port: 1204
   targetPort: 1204
+  dubbo_port: 2023
 resources:
   requests:
     cpu: 250m

+ 1 - 0
charts/shop-recycle-msg/values.yaml

@@ -9,6 +9,7 @@ service:
   type: ClusterIP
   port: 1217
   targetPort: 1217
+  dubbo_port: 2026
 resources:
   requests:
     cpu: 250m

+ 1 - 0
charts/shop-recycle-order-center/values.yaml

@@ -9,6 +9,7 @@ service:
   type: ClusterIP
   port: 1203
   targetPort: 1203
+  dubbo_port: 2022
 resources:
   requests:
     cpu: 250m

+ 1 - 0
charts/shop-recycle-order-search/values.yaml

@@ -9,6 +9,7 @@ service:
   type: ClusterIP
   port: 1238
   targetPort: 1238
+  dubbo_port: 2034
 resources:
   requests:
     cpu: 250m

+ 1 - 0
charts/shop-recycle-payment/values.yaml

@@ -9,6 +9,7 @@ service:
   type: ClusterIP
   port: 1218
   targetPort: 1218
+  dubbo_port: 2027
 resources:
   requests:
     cpu: 250m

+ 1 - 0
charts/shop-recycle-pis/values.yaml

@@ -9,6 +9,7 @@ service:
   type: ClusterIP
   port: 1209
   targetPort: 1209
+  dubbo_port: 2025
 resources:
   requests:
     cpu: 250m

+ 1 - 0
charts/shop-recycle-platform/values.yaml

@@ -9,6 +9,7 @@ service:
   type: ClusterIP
   port: 1201
   targetPort: 1201
+  dubbo_port: 2021
 resources:
   requests:
     cpu: 250m

+ 1 - 0
charts/shop-recycle-store/values.yaml

@@ -9,6 +9,7 @@ service:
   type: ClusterIP
   port: 1208
   targetPort: 1208
+  dubbo_port: 2024
 resources:
   requests:
     cpu: 250m

+ 1 - 0
charts/shop-recycle-wechat/values.yaml

@@ -9,6 +9,7 @@ service:
   type: ClusterIP
   port: 1231
   targetPort: 1231
+  dubbo_port: 2031
 resources:
   requests:
     cpu: 250m

+ 46 - 0
check_dubbo_ports.py

@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+import yaml
+from pathlib import Path
+
+repo_root = Path("d:/coding-area/devops/deploy/microservice-helm")
+chart_base = repo_root / "charts"
+
+# Get all service directories
+services = sorted([d.name for d in chart_base.iterdir() if d.is_dir() and d.name != "base"])
+
+dubbo_services = {}
+
+for service_name in services:
+    values_path = chart_base / service_name / "values.yaml"
+    
+    if not values_path.exists():
+        continue
+    
+    try:
+        with open(values_path, 'r', encoding='utf-8') as f:
+            values = yaml.safe_load(f)
+    except Exception as e:
+        print(f"ERROR reading {service_name}: {e}")
+        continue
+    
+    # Check if service has dubbo configuration
+    if values and 'config' in values and 'yml' in values['config']:
+        config_yml = values['config']['yml']
+        
+        # Look for dubbo protocol port
+        if 'dubbo' in config_yml and 'protocol' in config_yml['dubbo']:
+            protocol = config_yml['dubbo']['protocol']
+            if 'port' in protocol:
+                dubbo_port = protocol['port']
+                http_port = values['service']['port']
+                dubbo_services[service_name] = {
+                    'http_port': http_port,
+                    'dubbo_port': dubbo_port
+                }
+
+print(f"发现 {len(dubbo_services)} 个Dubbo服务:\n")
+for service_name in sorted(dubbo_services.keys()):
+    info = dubbo_services[service_name]
+    print(f"{service_name}:")
+    print(f"  HTTP Port: {info['http_port']}")
+    print(f"  Dubbo Port: {info['dubbo_port']}")