apiVersion: apps/v1
kind: Deployment
metadata:
  name: config-center
spec:
  replicas: 2
  selector:
    matchLabels:
      app: config-center
  template:
    metadata:
      labels:
        app: config-center
    spec:
      serviceAccountName: config-center-sa
      # config-center is on the cluster-provisioning ("开区") critical path; without a
      # high priority it gets preempted by provisioning pods under CPU pressure and then
      # cannot reschedule until the autoscaler adds nodes, briefly dropping to 0 ready
      # replicas and causing Kong "failure to get a peer from the ring-balancer" 503s.
      priorityClassName: system-cluster-critical
      # Keep the two replicas on different nodes so a single node/preemption event cannot
      # take out both at once.
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:
              labelSelector:
                matchLabels:
                  app: config-center
              topologyKey: kubernetes.io/hostname
      containers:
      - name: config-center
        command:
        - /config-center
        args:
          - --config=/etc/config-center/config.toml
        image: tidbcloud/config-center:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
          protocol: TCP
        - containerPort: 8081
          protocol: TCP
        resources:
          # requests were previously unset, so Kubernetes defaulted them to equal the
          # limits (2 cores / 1Gi). That huge reservation is why a preempted pod hit
          # "Insufficient cpu" and waited minutes for a node scale-up. Actual usage is
          # ~1m CPU / ~10Mi, so request a realistic floor and let limits cap bursts.
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 2000m
            memory: 1024Mi
        # No /healthz endpoint exists (8081 is a grpc-gateway mux), so gate readiness on
        # the HTTP port accepting connections. This keeps not-yet-serving pods out of the
        # Service Endpoints (and thus out of Kong's ring-balancer).
        readinessProbe:
          tcpSocket:
            port: 8081
          initialDelaySeconds: 3
          periodSeconds: 5
          failureThreshold: 3
        livenessProbe:
          tcpSocket:
            port: 8081
          initialDelaySeconds: 10
          periodSeconds: 10
          failureThreshold: 3
        volumeMounts:
        - mountPath: /etc/config-center
          name: config
          readOnly: true
        env:
          - name: DB_PASSWORD
            valueFrom:
              secretKeyRef:
                key: config-center-db-secret
                name: config-center-db-secret
      volumes:
      - name: config
        configMap:
          name: config-center-config
