title: 原生 Kubernetes API description: keywords:

    • rancher
    • rancher中文
    • rancher中文文档
    • rancher官网
    • rancher文档
    • Rancher
    • rancher 中文
    • rancher 中文文档
    • rancher cn
    • API
    • API Tokens
    • API指南
    • API参考
    • API资源类型

    Rancher UI 目前的 API 只支持一些常用资源处理,通过访问https://rancher_url/v3/可以查看到具体支持的类型。

    但是对于像ServiceAccount之类的资源,可通过 Rancher UI 代理去访问 K8S 直连 API,接口地址为:rancher_url/k8s/clusters/<集群ID>/api/<API版本>/<资源类型>

    ServiceAccount可以通过 rancher_url/k8s/clusters/<集群ID>/api/v1/serviceaccounts去查看所有的ServiceAccountList,例如访问:https://rancher_url/k8s/clusters/c-nlbtk/api/v1/serviceaccounts,会返回如下结果:

    1. {
    2. "kind": "ServiceAccountList",
    3. "apiVersion": "v1",
    4. "metadata": {
    5. "selfLink": "/api/v1/serviceaccounts",
    6. "resourceVersion": "9972577"
    7. },
    8. "items": [
    9. {
    10. "metadata": {
    11. "name": "default",
    12. "namespace": "cattle-logging",
    13. "selfLink": "/api/v1/namespaces/cattle-logging/serviceaccounts/default",
    14. "uid": "f570131c-f3eb-4018-8119-85c1544f5750",
    15. "resourceVersion": "3531475",
    16. "creationTimestamp": "2019-10-30T03:24:36Z"
    17. },
    18. "secrets": [
    19. {
    20. "name": "default-token-w6pjb"
    21. }
    22. ]
    23. },

    您可以通过命名空间筛选 Service Account,例如:https://rancher_url/k8s/clusters/<cluster——id>/api/v1/namespaces/cattle-logging/serviceaccounts/namespaces/cattle-logging/serviceaccounts是一种过滤方式,表示只返回该命名空间下的 Service Account 列表。

    1. {
    2. "kind": "ServiceAccountList",
    3. "apiVersion": "v1",
    4. "metadata": {
    5. "selfLink": "/api/v1/namespaces/cattle-logging/serviceaccounts",
    6. "resourceVersion": "9973445"
    7. },
    8. "items": [
    9. {
    10. "metadata": {
    11. "name": "default",
    12. "namespace": "cattle-logging",
    13. "selfLink": "/api/v1/namespaces/cattle-logging/serviceaccounts/default",
    14. "uid": "f570131c-f3eb-4018-8119-85c1544f5750",
    15. "resourceVersion": "3531475",
    16. "creationTimestamp": "2019-10-30T03:24:36Z"
    17. },
    18. "secrets": [
    19. {
    20. "name": "default-token-w6pjb"
    21. }
    22. ]
    23. },
    24. {
    25. "metadata": {
    26. "name": "rancher-logging-fluentd",
    27. "namespace": "cattle-logging",
    28. "selfLink": "/api/v1/namespaces/cattle-logging/serviceaccounts/rancher-logging-fluentd",
    29. "uid": "9024070c-152c-4106-9571-e6503ce37cdf",
    30. "resourceVersion": "3531508",
    31. "creationTimestamp": "2019-10-30T03:24:41Z",
    32. "labels": {
    33. "app": "fluentd",
    34. "chart": "fluentd-0.0.2",
    35. "heritage": "Tiller",
    36. "io.cattle.field/appId": "rancher-logging",
    37. "release": "rancher-logging"
    38. }
    39. },
    40. "secrets": [
    41. {
    42. "name": "rancher-logging-fluentd-token-d7lww"
    43. }
    44. ]
    45. },
    46. {
    47. "metadata": {
    48. "name": "rancher-logging-log-aggregator",
    49. "namespace": "cattle-logging",
    50. "selfLink": "/api/v1/namespaces/cattle-logging/serviceaccounts/rancher-logging-log-aggregator",
    51. "uid": "f5d25650-acba-4e00-b0b0-723aa138b71f",
    52. "resourceVersion": "3531514",
    53. "creationTimestamp": "2019-10-30T03:24:41Z",
    54. "labels": {
    55. "app": "log-aggregator",
    56. "chart": "log-aggregator-0.0.2",
    57. "heritage": "Tiller",
    58. "io.cattle.field/appId": "rancher-logging",
    59. "release": "rancher-logging"
    60. }
    61. },
    62. "secrets": [
    63. {
    64. "name": "rancher-logging-log-aggregator-token-6pnsg"
    65. }
    66. ]
    67. }
    68. ]
    69. }