kubernetes-使用kubectl访问kubernetes API

查询所有api:
$ kubectl get apiservice 
NAME                                    AGE
v1.                                     1d
v1.apps                                 1d
v1.authentication.k8s.io                1d
v1.authorization.k8s.io                 1d
v1.autoscaling                          1d
v1.batch                                1d
v1.networking.k8s.io                    1d
v1.rbac.authorization.k8s.io            1d
v1.storage.k8s.io                       1d
v1alpha1.admissionregistration.k8s.io   3h
v1alpha1.rbac.authorization.k8s.io      2h
v1alpha1.scheduling.k8s.io              2h
v1alpha1.settings.k8s.io                2h
v1alpha1.storage.k8s.io                 2h
v1beta1.admissionregistration.k8s.io    1d
v1beta1.apiextensions.k8s.io            1d
v1beta1.apps                            1d
v1beta1.authentication.k8s.io           1d
v1beta1.authorization.k8s.io            1d
v1beta1.batch                           1d
v1beta1.certificates.k8s.io             1d
v1beta1.events.k8s.io                   1d
v1beta1.extensions                      1d
v1beta1.metrics.k8s.io                  2h
v1beta1.policy                          1d
v1beta1.rbac.authorization.k8s.io       1d
v1beta1.storage.k8s.io                  1d
v1beta2.apps                            1d
v2alpha1.batch                          2h
v2beta1.autoscaling                     1d

查看指定的api:
$ kubectl get apiservice v2beta1.autoscaling -o yaml
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
  creationTimestamp: 2018-06-27T06:40:59Z
  labels:
    kube-aggregator.kubernetes.io/automanaged: onstart
  name: v2beta1.autoscaling
  resourceVersion: "24"
  selfLink: /apis/apiregistration.k8s.io/v1/apiservices/v2beta1.autoscaling
  uid: 0d336ee9-79d5-11e8-a663-08002768bc4c
spec:
  caBundle: null
  group: autoscaling
  groupPriorityMinimum: 17500
  service: null
  version: v2beta1
  versionPriority: 9
status:
  conditions:
  - lastTransitionTime: 2018-06-27T06:40:59Z
    message: Local APIServices are always available
    reason: Local
    status: "True"
    type: Available

访问api:
$ kubectl get --raw=/apis/autoscaling/v2beta1 |jq .
{
  "kind": "APIResourceList",
  "apiVersion": "v1",
  "groupVersion": "autoscaling/v2beta1",
  "resources": [
    {
      "name": "horizontalpodautoscalers",
      "singularName": "",
      "namespaced": true,
      "kind": "HorizontalPodAutoscaler",
      "verbs": [
        "create",
        "delete",
        "deletecollection",
        "get",
        "list",
        "patch",
        "update",
        "watch"
      ],
      "shortNames": [
        "hpa"
      ],
      "categories": [
        "all"
      ]
    },
    {
      "name": "horizontalpodautoscalers/status",
      "singularName": "",
      "namespaced": true,
      "kind": "HorizontalPodAutoscaler",
      "verbs": [
        "get",
        "patch",
        "update"
      ]
    }
  ]
}

其他:

1. 使用curl访问kubernetes API (https、RBAC认证)

2. 使用kubectl proxy 访问kubernetes API

3. 一个访问 metrcs-server api的例子

你可能感兴趣的:(kubernetes)