试图让 Traefik 识别 CockroachDB 仪表板

Trying to get Traefik to recognise the CockroachDB dashboard

我安装了 CockroachDB (CD) 使用:

helm install --name my-release-cockroachdb stable/cockroachdb

因为这个创建的服务,我期待 Traefik 找到 CockroachDB 仪表板,但它没有。创建的服务是:

{
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "my-release-cockroachdb-cockroachdb",
    "namespace": "default",
    "selfLink": "/api/v1/namespaces/default/services/my-release-cockroachdb-cockroachdb",
    "uid": "00316801-a468-11e8-8b41-00155d296111",
    "resourceVersion": "16247",
    "creationTimestamp": "2018-08-20T10:58:42Z",
    "labels": {
      "chart": "cockroachdb-1.2.2",
      "component": "my-release-cockroachdb-cockroachdb",
      "heritage": "Tiller",
      "release": "my-release-cockroachdb"
    },
    "annotations": {
      "prometheus.io/path": "_status/vars",
      "prometheus.io/port": "8080",
      "prometheus.io/scrape": "true",
      "service.alpha.kubernetes.io/tolerate-unready-endpoints": "true"
    }
  },
  "spec": {
    "ports": [
      {
        "name": "grpc",
        "protocol": "TCP",
        "port": 26257,
        "targetPort": 26257
      },
      {
        "name": "http",
        "protocol": "TCP",
        "port": 8081,
        "targetPort": 8081
      }
    ],
    "selector": {
      "component": "my-release-cockroachdb-cockroachdb"
    },
    "clusterIP": "None",
    "type": "ClusterIP",
    "sessionAffinity": "None",
    "publishNotReadyAddresses": true
  },
  "status": {
    "loadBalancer": {}
  }
}

{
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "my-release-cockroachdb-cockroachdb-public",
    "namespace": "default",
    "selfLink": "/api/v1/namespaces/default/services/my-release-cockroachdb-cockroachdb-public",
    "uid": "002ec344-a468-11e8-8b41-00155d296111",
    "resourceVersion": "16186",
    "creationTimestamp": "2018-08-20T10:58:42Z",
    "labels": {
      "chart": "cockroachdb-1.2.2",
      "component": "my-release-cockroachdb-cockroachdb",
      "heritage": "Tiller",
      "release": "my-release-cockroachdb"
    }
  },
  "spec": {
    "ports": [
      {
        "name": "grpc",
        "protocol": "TCP",
        "port": 26257,
        "targetPort": 26257
      },
      {
        "name": "http",
        "protocol": "TCP",
        "port": 8081,
        "targetPort": 8081
      }
    ],
    "selector": {
      "component": "my-release-cockroachdb-cockroachdb"
    },
    "clusterIP": "10.105.70.122",
    "type": "ClusterIP",
    "sessionAffinity": "None"
  },
  "status": {
    "loadBalancer": {}
  }
}

最终告诉我可以使用:

kubectl port-forward my-release-cockroachdb-cockroachdb-0 8080

访问 CD 仪表板。正如我认为 Traefik 已经消耗了 8080,我编辑了服务(如您在上面看到的那样使用 8081)然后:

kubectl port-forward my-release-cockroachdb-cockroachdb-0 8081

但这会产生:

E0820 21:33:59.676164  432152 portforward.go:331] an error occurred forwarding 8081 -> 8081: error forwarding port 8081 to pod 8b7db5a2feed08f1bc329db69f9623a0c548d5ffae002236c5d7a4181ba326d3, uid : exit status 1: 2018/08/20 11:33:57 socat[44354] E connect(5, AF=2 127.0.0.1:8081, 16): Connection refused
E0820 21:33:59.681160  432152 portforward.go:331] an error occurred forwarding 8081 -> 8081: error forwarding port 8081 to pod 8b7db5a2feed08f1bc329db69f9623a0c548d5ffae002236c5d7a4181ba326d3, uid : exit status 1: 2018/08/20 11:33:57 socat[44355] E connect(5, AF=2 127.0.0.1:8081, 16): Connection refused

所以我的问题是:

  1. 如何让 Traefik 自动检测 CockroachDB 服务,尤其是 CockroachDB 管理 GUI
  2. 如何连接到 Traefik 后面的 Cockroach Admin GUI?

cockroach-statefulset.yaml from the helm chart never sets the http port in the start command.

您需要:

  • 将 CockroachDB UI 的端口保持在 :8080
  • 或者:正确地将自定义端口一直传递到 cockroach start 命令行。这可以通过 --http-port 标志来完成。