apecloud / kubeblocks

KubeBlocks is an open-source control plane software that runs and manages databases, message queues and other stateful applications on K8s.
https://kubeblocks.io
GNU Affero General Public License v3.0
2.12k stars 175 forks source link

[BUG] tidb cluster creation failed #7923

Closed haowen159 closed 3 months ago

haowen159 commented 3 months ago

Describe the bug A clear and concise description of what the bug is.

kbcli version
Kubernetes: v1.28.11-gke.1019001
KubeBlocks: 1.0.0-alpha.1
kbcli: 1.0.0-alpha.0

To Reproduce Steps to reproduce the behavior:

  1. cluster yaml
    
    apiVersion: apps.kubeblocks.io/v1alpha1
    kind: Cluster
    metadata:
    name: tidb-cluster
    namespace: default
    spec:
    terminationPolicy: Delete
    componentSpecs:
    - name: pd
    componentDef: tidb-pd
    serviceAccountName: kb-tidb-cluster
    replicas: 1
    resources:
      limits:
        cpu: '1'
        memory: 2Gi
      requests:
        cpu: '1'
        memory: 2Gi
    volumeClaimTemplates:
    - name: data
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
    - name: tikv
    componentDef: tikv
    replicas: 1
    resources:
      limits:
        cpu: '1'
        memory: 2Gi
      requests:
        cpu: '1'
        memory: 2Gi
    volumeClaimTemplates:
    - name: data
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
    - name: tidb
    componentDef: tidb
    replicas: 1
    resources:
      limits:
        cpu: '1'
        memory: 2Gi
      requests:
        cpu: '1'
        memory: 2Gi
    volumeClaimTemplates:
    - name: data
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
2. see error

k get cluster NAME CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS AGE tidb-cluster Delete 13m k get pod NAME READY STATUS RESTARTS AGE tidb-cluster-pd-0 4/4 Running 0 13m tidb-cluster-tidb-0 4/4 Running 0 13m k get cmp NAME DEFINITION SERVICE-VERSION STATUS AGE tidb-cluster-pd tidb-pd-7 7.5.2 Running 13m tidb-cluster-tidb tidb-pd-7 7.5.2 Running 13m tidb-cluster-tikv tikv-7 7.5.2 13m

3.describe cmp

k describe cmp tidb-cluster-tikv
Name: tidb-cluster-tikv Namespace: default Labels: app.kubernetes.io/instance=tidb-cluster app.kubernetes.io/managed-by=kubeblocks apps.kubeblocks.io/cluster-uid=16fb221d-6304-49cc-8f6c-a973383ee99e apps.kubeblocks.io/component-name=tikv componentdefinition.kubeblocks.io/name=tikv-7 Annotations: kubeblocks.io/generation: 2 API Version: apps.kubeblocks.io/v1alpha1 Kind: Component Metadata: Creation Timestamp: 2024-08-05T08:33:48Z Finalizers: cluster.kubeblocks.io/finalizer component.kubeblocks.io/finalizer Generation: 1 Owner References: API Version: apps.kubeblocks.io/v1alpha1 Block Owner Deletion: true Controller: true Kind: Cluster Name: tidb-cluster UID: 16fb221d-6304-49cc-8f6c-a973383ee99e Resource Version: 27889072 UID: 5d00ec3e-d803-47e0-8fed-ecc9f5c772ad Spec: Comp Def: tikv-7 Replicas: 1 Resources: Limits: Cpu: 1 Memory: 2Gi Requests: Cpu: 1 Memory: 2Gi Scheduling Policy: Affinity: Node Affinity: Preferred During Scheduling Ignored During Execution: Preference: Match Expressions: Key: kb-data Operator: In Values: true Weight: 100 Tolerations: Effect: NoSchedule Key: kb-data Operator: Equal Value: true Service Version: 7.5.2 Volume Claim Templates: Name: data Spec: Access Modes: ReadWriteOnce Resources: Requests: Storage: 20Gi Status: Conditions: Last Transition Time: 2024-08-05T08:33:48Z Message: The operator has started the provisioning of Cluster: tidb-cluster-tikv Observed Generation: 1 Reason: PreCheckSucceed Status: True Type: ProvisioningStarted Events: Type Reason Age From Message


Warning Warning 89s component-controller has no Service object found when resolving vars Warning Warning 46s (x6 over 89s) component-controller resolving vars from Service object error: more than one referent component found: pd,tidb Warning Warning 5s (x7 over 88s) component-controller resolving vars from Service object error: more than one referent component found: tidb,pd



**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
 - OS: [e.g. iOS]
 - Browser [e.g. chrome, safari]
 - Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
cjc7373 commented 3 months ago

The problem is that you ref tidb component as componentDef: tidb. However, our compdef names for tidb and pd are tidb-pd-7 and tidb-7. They share the same prefix tidb. So your ref is too vague to match the correct compdef. In this case, it actually matched tidb-pd-7 for component tidb. Thus caused the problem.