1. Kubernetes api versions清单

如下是Kubernetes 1.18.5 下的API版本清单

# kubectl api-versions   前一部分是apigroup,后一部分是版本
admissionregistration.k8s.io/v1
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
autoscaling/v2beta2
batch/v1
batch/v1beta1
certificates.k8s.io/v1beta1
coordination.k8s.io/v1
coordination.k8s.io/v1beta1
crd.projectcalico.org/v1
discovery.k8s.io/v1beta1
events.k8s.io/v1beta1
extensions/v1beta1
networking.k8s.io/v1
networking.k8s.io/v1beta1
node.k8s.io/v1beta1
policy/v1beta1
rbac.authorization.k8s.io/v1
rbac.authorization.k8s.io/v1beta1
scheduling.k8s.io/v1
scheduling.k8s.io/v1beta1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1

2. 各api_group包含的资源类型

这里举例的api_group为核心API组(’ ')以及 apps组下的资源类型

2.1 核心API组(’ ')下的资源类型

# kubectl api-resources --api-group='' -o wide
NAME                     SHORTNAMES   APIGROUP   NAMESPACED   KIND                    VERBS
bindings                                         true         Binding                 [create]
componentstatuses        cs                      false        ComponentStatus         [get list]
configmaps               cm                      true         ConfigMap               [create delete deletecollection get list patch update watch]
endpoints                ep                      true         Endpoints               [create delete deletecollection get list patch update watch]
events                   ev                      true         Event                   [create delete deletecollection get list patch update watch]
limitranges              limits                  true         LimitRange              [create delete deletecollection get list patch update watch]
namespaces               ns                      false        Namespace               [create delete get list patch update watch]
nodes                    no                      false        Node                    [create delete deletecollection get list patch update watch]
persistentvolumeclaims   pvc                     true         PersistentVolumeClaim   [create delete deletecollection get list patch update watch]
persistentvolumes        pv                      false        PersistentVolume        [create delete deletecollection get list patch update watch]
pods                     po                      true         Pod                     [create delete deletecollection get list patch update watch]
podtemplates                                     true         PodTemplate             [create delete deletecollection get list patch update watch]
replicationcontrollers   rc                      true         ReplicationController   [create delete deletecollection get list patch update watch]
resourcequotas           quota                   true         ResourceQuota           [create delete deletecollection get list patch update watch]
secrets                                          true         Secret                  [create delete deletecollection get list patch update watch]
serviceaccounts          sa                      true         ServiceAccount          [create delete deletecollection get list patch update watch]
services                 svc                     true         Service                 [create delete get list patch update watch]

2.2 apps组下的资源类型

# kubectl api-resources --api-group='apps' -o wide
NAME                  SHORTNAMES   APIGROUP   NAMESPACED   KIND                 VERBS
controllerrevisions                apps       true         ControllerRevision   [create delete deletecollection get list patch update watch]
daemonsets            ds           apps       true         DaemonSet            [create delete deletecollection get list patch update watch]
deployments           deploy       apps       true         Deployment           [create delete deletecollection get list patch update watch]
replicasets           rs           apps       true         ReplicaSet           [create delete deletecollection get list patch update watch]
statefulsets          sts          apps       true         StatefulSet          [create delete deletecollection get list patch update watch]

3. 资源对象与namespace的关系

3.1 在namespace中的资源对象

# kubectl api-resources --namespaced=true
NAME                        SHORTNAMES   APIGROUP                    NAMESPACED   KIND
bindings                                                             true         Binding
configmaps                  cm                                       true         ConfigMap
endpoints                   ep                                       true         Endpoints
events                      ev                                       true         Event
limitranges                 limits                                   true         LimitRange
persistentvolumeclaims      pvc                                      true         PersistentVolumeClaim
pods                        po                                       true         Pod
podtemplates                                                         true         PodTemplate
replicationcontrollers      rc                                       true         ReplicationController
resourcequotas              quota                                    true         ResourceQuota
secrets                                                              true         Secret
serviceaccounts             sa                                       true         ServiceAccount
services                    svc                                      true         Service
controllerrevisions                      apps                        true         ControllerRevision
daemonsets                  ds           apps                        true         DaemonSet
deployments                 deploy       apps                        true         Deployment
replicasets                 rs           apps                        true         ReplicaSet
statefulsets                sts          apps                        true         StatefulSet
localsubjectaccessreviews                authorization.k8s.io        true         LocalSubjectAccessReview
horizontalpodautoscalers    hpa          autoscaling                 true         HorizontalPodAutoscaler
cronjobs                    cj           batch                       true         CronJob
jobs                                     batch                       true         Job
leases                                   coordination.k8s.io         true         Lease
networkpolicies                          crd.projectcalico.org       true         NetworkPolicy
networksets                              crd.projectcalico.org       true         NetworkSet
endpointslices                           discovery.k8s.io            true         EndpointSlice
events                      ev           events.k8s.io               true         Event
ingresses                   ing          extensions                  true         Ingress
ingresses                   ing          networking.k8s.io           true         Ingress
networkpolicies             netpol       networking.k8s.io           true         NetworkPolicy
poddisruptionbudgets        pdb          policy                      true         PodDisruptionBudget
rolebindings                             rbac.authorization.k8s.io   true         RoleBinding
roles                                    rbac.authorization.k8s.io   true         Role

3.2 不在namespace中的资源对象

# kubectl api-resources --namespaced=false
NAME                              SHORTNAMES   APIGROUP                       NAMESPACED   KIND
componentstatuses                 cs                                          false        ComponentStatus
namespaces                        ns                                          false        Namespace
nodes                             no                                          false        Node
persistentvolumes                 pv                                          false        PersistentVolume
mutatingwebhookconfigurations                  admissionregistration.k8s.io   false        MutatingWebhookConfiguration
validatingwebhookconfigurations                admissionregistration.k8s.io   false        ValidatingWebhookConfiguration
customresourcedefinitions         crd,crds     apiextensions.k8s.io           false        CustomResourceDefinition
apiservices                                    apiregistration.k8s.io         false        APIService
tokenreviews                                   authentication.k8s.io          false        TokenReview
selfsubjectaccessreviews                       authorization.k8s.io           false        SelfSubjectAccessReview
selfsubjectrulesreviews                        authorization.k8s.io           false        SelfSubjectRulesReview
subjectaccessreviews                           authorization.k8s.io           false        SubjectAccessReview
certificatesigningrequests        csr          certificates.k8s.io            false        CertificateSigningRequest
bgpconfigurations                              crd.projectcalico.org          false        BGPConfiguration
bgppeers                                       crd.projectcalico.org          false        BGPPeer
blockaffinities                                crd.projectcalico.org          false        BlockAffinity
clusterinformations                            crd.projectcalico.org          false        ClusterInformation
felixconfigurations                            crd.projectcalico.org          false        FelixConfiguration
globalnetworkpolicies                          crd.projectcalico.org          false        GlobalNetworkPolicy
globalnetworksets                              crd.projectcalico.org          false        GlobalNetworkSet
hostendpoints                                  crd.projectcalico.org          false        HostEndpoint
ipamblocks                                     crd.projectcalico.org          false        IPAMBlock
ipamconfigs                                    crd.projectcalico.org          false        IPAMConfig
ipamhandles                                    crd.projectcalico.org          false        IPAMHandle
ippools                                        crd.projectcalico.org          false        IPPool
kubecontrollersconfigurations                  crd.projectcalico.org          false        KubeControllersConfiguration
ingressclasses                                 networking.k8s.io              false        IngressClass
runtimeclasses                                 node.k8s.io                    false        RuntimeClass
podsecuritypolicies               psp          policy                         false        PodSecurityPolicy
clusterrolebindings                            rbac.authorization.k8s.io      false        ClusterRoleBinding
clusterroles                                   rbac.authorization.k8s.io      false        ClusterRole
priorityclasses                   pc           scheduling.k8s.io              false        PriorityClass
csidrivers                                     storage.k8s.io                 false        CSIDriver
csinodes                                       storage.k8s.io                 false        CSINode
storageclasses                    sc           storage.k8s.io                 false        StorageClass
volumeattachments                              storage.k8s.io                 false        VolumeAttachment

4. 同一个apigroup可能存在多个版本,到底用那个呢

我们可以选择当前Kubernetes版本(例如1.16.x)推荐的版本 :preferredVersion,例如

# kubectl get --raw "/apis" |python -mjson.tool
# 选择个apigroup中的preferredVersion
{   "kind": "APIGroupList"
    "apiVersion": "v1",
    "groups": [
        {   "name": "apiregistration.k8s.io",
            "preferredVersion": {"groupVersion": "apiregistration.k8s.io/v1","version": "v1"},
            "versions": [{"groupVersion": "apiregistration.k8s.io/v1",       "version": "v1"},
                         {"groupVersion": "apiregistration.k8s.io/v1beta1",  "version": "v1beta1"}]
        },
        {   "name": "extensions",
            "preferredVersion": {"groupVersion": "extensions/v1beta1", "version": "v1beta1"},
            "versions": [{"groupVersion": "extensions/v1beta1",        "version": "v1beta1"}]
        },
        {
            "name": "apps",
            "preferredVersion": {"groupVersion": "apps/v1", "version": "v1"},
            "versions": [{"groupVersion": "apps/v1",        "version": "v1"}]
        },
        {
            "name": "events.k8s.io",
            "preferredVersion": {"groupVersion": "events.k8s.io/v1beta1", "version": "v1beta1"},
            "versions": [{"groupVersion": "events.k8s.io/v1beta1",        "version": "v1beta1"}]
        },
        {
            "name": "authentication.k8s.io",
            "preferredVersion": {"groupVersion": "authentication.k8s.io/v1", "version": "v1"},
            "versions": [{"groupVersion": "authentication.k8s.io/v1",        "version": "v1"},
                         {"groupVersion": "authentication.k8s.io/v1beta1",   "version": "v1beta1"}]
        },
        {
            "name": "authorization.k8s.io",
            "preferredVersion": {"groupVersion": "authorization.k8s.io/v1", "version": "v1"},
            "versions": [{"groupVersion": "authorization.k8s.io/v1",        "version": "v1"},
                         {"groupVersion": "authorization.k8s.io/v1beta1",   "version": "v1beta1"}]
        },
        {
            "name": "autoscaling",
            "preferredVersion": {"groupVersion": "autoscaling/v1", "version": "v1"},
            "versions": [{"groupVersion": "autoscaling/v1",        "version": "v1"},
                         {"groupVersion": "autoscaling/v2beta1",   "version": "v2beta1"},
                         {"groupVersion": "autoscaling/v2beta2",   "version": "v2beta2"}]
        },
        {
            "name": "batch",
            "preferredVersion": {"groupVersion": "batch/v1", "version": "v1"},
            "versions": [{"groupVersion": "batch/v1",        "version": "v1"},
                         {"groupVersion": "batch/v1beta1",   "version": "v1beta1"}]
        },
        {
            "name": "certificates.k8s.io",
            "preferredVersion": {"groupVersion": "certificates.k8s.io/v1beta1", "version": "v1beta1"},
            "versions": [{"groupVersion": "certificates.k8s.io/v1beta1",        "version": "v1beta1"}]
        },
        {
            "name": "networking.k8s.io",
            "preferredVersion": {"groupVersion": "networking.k8s.io/v1", "version": "v1"},
            "versions": [{"groupVersion": "networking.k8s.io/v1",        "version": "v1"},
                         {"groupVersion": "networking.k8s.io/v1beta1",   "version": "v1beta1"}]
        },
        {
            "name": "policy",
            "preferredVersion": {"groupVersion": "policy/v1beta1", "version": "v1beta1"},
            "versions": [{"groupVersion": "policy/v1beta1",        "version": "v1beta1"}]
        },
        {
            "name": "rbac.authorization.k8s.io",
            "preferredVersion": {"groupVersion": "rbac.authorization.k8s.io/v1", "version": "v1"},
            "versions": [{"groupVersion": "rbac.authorization.k8s.io/v1",        "version": "v1"},
                         {"groupVersion": "rbac.authorization.k8s.io/v1beta1",   "version": "v1beta1"}]
        },
        {
            "name": "storage.k8s.io",
            "preferredVersion": {"groupVersion": "storage.k8s.io/v1", "version": "v1"},
            "versions": [{"groupVersion": "storage.k8s.io/v1",        "version": "v1beta1"}]
        },
        {
            "name": "admissionregistration.k8s.io",
            "preferredVersion": {"groupVersion": "admissionregistration.k8s.io/v1", "version": "v1"},
            "versions": [{"groupVersion": "admissionregistration.k8s.io/v1",        "version": "v1"},
                         {"groupVersion": "admissionregistration.k8s.io/v1beta1",   "version": "v1beta1"}]
        },
        {
            "name": "apiextensions.k8s.io",
            "preferredVersion": {"groupVersion": "apiextensions.k8s.io/v1", "version": "v1"},
            "versions": [{"groupVersion": "apiextensions.k8s.io/v1",        "version": "v1"},
                         {"groupVersion": "apiextensions.k8s.io/v1beta1",   "version": "v1beta1"}]
        },
        {
            "name": "scheduling.k8s.io",
            "preferredVersion": {"groupVersion": "scheduling.k8s.io/v1", "version": "v1"},
            "versions": [{"groupVersion": "scheduling.k8s.io/v1",        "version": "v1"},
                         {"groupVersion": "scheduling.k8s.io/v1beta1",   "version": "v1beta1"}]
        },
        {
            "name": "coordination.k8s.io",
            "preferredVersion": {"groupVersion": "coordination.k8s.io/v1", "version": "v1"},
            "versions": [{"groupVersion": "coordination.k8s.io/v1",        "version": "v1"},
                         {"groupVersion": "coordination.k8s.io/v1beta1",   "version": "v1beta1"}]
        },
        {
            "name": "node.k8s.io",
            "preferredVersion": {"groupVersion": "node.k8s.io/v1beta1", "version": "v1beta1"},
            "versions": [{"groupVersion": "node.k8s.io/v1beta1",        "version": "v1beta1"}]
        },
        {
            "name": "crd.projectcalico.org",
            "preferredVersion": {"groupVersion": "crd.projectcalico.org/v1", "version": "v1"},
            "versions": [{"groupVersion": "crd.projectcalico.org/v1",        "version": "v1"}]
        },
        {
            "name": "traefik.containo.us",
            "preferredVersion": {"groupVersion": "traefik.containo.us/v1alpha1", "version": "v1alpha1"},
            "versions": [{"groupVersion": "traefik.containo.us/v1alpha1",        "version": "v1alpha1"}]
        },
        {
            "name": "metrics.k8s.io",
            "preferredVersion": {"groupVersion": "metrics.k8s.io/v1beta1", "version": "v1beta1"},
            "versions": [{"groupVersion": "metrics.k8s.io/v1beta1",        "version": "v1beta1"}]
        }
    ]
}
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐