pingcap / tidb-operator

TiDB operator creates and manages TiDB clusters running in Kubernetes.
https://docs.pingcap.com/tidb-in-kubernetes/
Apache License 2.0
1.22k stars 493 forks source link

Add label to identify individual services #2622

Closed kolbe closed 4 years ago

kolbe commented 4 years ago

Feature Request

Is your feature request related to a problem? Please describe:

Service labels facilitate identifying certain types of services but don't quite facilitate identifying an individual service. For example, the prometheus and grafana services have the same labels:

Name:              tidb-prometheus
Namespace:         tinewswriter-tidb
Labels:            app.kubernetes.io/component=monitor
                   app.kubernetes.io/instance=tidb
                   app.kubernetes.io/managed-by=tidb-operator
                   app.kubernetes.io/name=tidb-cluster

Name:              tidb-grafana
Namespace:         tinewswriter-tidb
Labels:            app.kubernetes.io/component=monitor
                   app.kubernetes.io/instance=tidb
                   app.kubernetes.io/managed-by=tidb-operator
                   app.kubernetes.io/name=tidb-cluster
$ kubectl get svc basic-tidb-peer -o json | jq .metadata.labels
{
  "app.kubernetes.io/component": "tidb",
  "app.kubernetes.io/instance": "basic",
  "app.kubernetes.io/managed-by": "tidb-operator",
  "app.kubernetes.io/name": "tidb-cluster"
}
$ kubectl get svc basic-tidb -o json | jq .metadata.labels
{
  "app.kubernetes.io/component": "tidb",
  "app.kubernetes.io/instance": "basic",
  "app.kubernetes.io/managed-by": "tidb-operator",
  "app.kubernetes.io/name": "tidb-cluster"
}

But it just isn't useful to see the basic-tidb service alongside the basic-tidb-peer service, since one of them presents connection end points to end-users and the other is meant to be used internally.

$ kubectl get svc -A -l app.kubernetes.io/component=tidb
NAMESPACE   NAME              TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)              AGE
default     basic-tidb        ClusterIP   10.108.16.250   <none>        4000/TCP,10080/TCP   17m
default     basic-tidb-peer   ClusterIP   None            <none>        10080/TCP            17m

Describe the feature you'd like:

Add a label that allows the end user to identify each actual, end-user-accessible service individually.

Describe alternatives you've considered:

Teachability, Documentation, Adoption, Migration Strategy:

zjj2wry commented 4 years ago

I think it makes sense for the service to have a unique label, for example, promethus operator has ServiceMonitor crd to find the corresponding service through the label.

mikechengwei commented 4 years ago

I think i can do it in this pr #2176

mikechengwei commented 4 years ago

I found this feature have finished in #2654 , i will fix my code.