相关文章:
【k8s】API Group 群组
【k8s】Kubernetes 声明式 API(apply)、命令式(patch)
【k8s】Kubernetes API 概念(声明式、命令式)

1. 概述

在使用k8s进行服务的部署过程中我们会使用到Deployment、Service、Pod等资源,在 yaml 文件中我们需要指定对应的 API 版本,我们可以通过访问相应的接口来管理相应的资源信息,在 k8s 中为了提高 API 的可扩展性,采用了 API Groups 进行标识这些接口,在 client-go 源码中就是通过指定的 API Groups 来访问 k8s 集群的,这里向大家介绍 API Groups 都有哪些,希望对你有帮助。

2. 分组

分组就是 把资源分为多个模块,一个组就是一个模块

k8s的api以层级结构组织在一起,每个api群组表现为一个以/apis为根路径的rest路径,不过核心群组core有一个专用的简化路径“/api/v1”.目前,常用的api群组分为两类:

  • 核心群组 或core API GROUP:rest路径为/api/v1,在资源的配置信息apiversion字段中引用时不指定路径,而仅给出版本,如“apiVersion:v1”。
    在权限定义

    rules:
    - apiGroups: [""]     //空字符串就是指Core API GROUP
      resources: ["pod"]
    
  • 命名的群组:rest路径为/apis/$GROUP_NAME/$VERSION,例如/apis/apps/v1,它在apiversion字段中引用的格式为:“apiVersion:$GROUP_NAME/$VERSION”,例如 apiVersion: batch/v1

2.1. Core Groups(核心组)

该分组也可以称之为 Legacy Groups,作为 k8s 最核心的 API ,其特点是没有组的概念,例如 “v1”,在资源对象的定义中表示为 “apiVersion: v1”,属于核心组的资源主要有下面几种:

  • Container
  • Pod
  • ReplicationController
  • Endpoint
  • Service
  • ConfigMap
  • Secret
  • Volume
  • PersistentVolumeClaim
  • Event
  • LimitRange
  • PodTemplate
  • Binding
  • ComponentStatus
  • Namespace
  • Node

2.2. 具有分组信息的 API

命名的群组:rest路径为/apis/$GROUP_NAME/$VERSION,例如/apis/apps/v1,它在apiversion字段中引用的格式为:“apiVersion:$GROUP_NAME/$VERSION”,例如 apiVersion: batch/v1

例如 “apiVersion: batch/v1”,常见的 Group 及资源对象主要有下面几种:

apps/v1

  • DaemonSet
  • Deployment
  • StatefulSet
  • ReplicaSet

batch/v1

  • Job

batch/v1beta

  • CronJob

3. 全量的apiversion 、group 、kind表

kubectl api-resources 打印全部的资源api和资源对象

  • v1是指默认的 core 分组
  • kubectl api-resources --api-group=apps 查看apps分组的资源对象
  • 可以使用 kubectl api-resources --api-group= 查看core分组的资源对象
NAME                                      SHORTNAMES          APIVERSION                                 NAMESPACED   KIND
bindings                                                      v1                                         true         Binding
componentstatuses                         cs                  v1                                         false        ComponentStatus
configmaps                                cm                  v1                                         true         ConfigMap
endpoints                                 ep                  v1                                         true         Endpoints
events                                    ev                  v1                                         true         Event
limitranges                               limits              v1                                         true         LimitRange
namespaces                                ns                  v1                                         false        Namespace
nodes                                     no                  v1                                         false        Node
persistentvolumeclaims                    pvc                 v1                                         true         PersistentVolumeClaim
persistentvolumes                         pv                  v1                                         false        PersistentVolume
pods                                      po                  v1                                         true         Pod
podtemplates                                                  v1                                         true         PodTemplate
replicationcontrollers                    rc                  v1                                         true         ReplicationController
resourcequotas                            quota               v1                                         true         ResourceQuota
secrets                                                       v1                                         true         Secret
serviceaccounts                           sa                  v1                                         true         ServiceAccount
services                                  svc                 v1                                         true         Service
mutatingwebhookconfigurations                                 admissionregistration.k8s.io/v1            false        MutatingWebhookConfiguration
validatingwebhookconfigurations                               admissionregistration.k8s.io/v1            false        ValidatingWebhookConfiguration
customresourcedefinitions                 crd,crds            apiextensions.k8s.io/v1                    false        CustomResourceDefinition
apiservices                                                   apiregistration.k8s.io/v1                  false        APIService
controllerrevisions                                           apps/v1                                    true         ControllerRevision
daemonsets                                ds                  apps/v1                                    true         DaemonSet
deployments                               deploy              apps/v1                                    true         Deployment
replicasets                               rs                  apps/v1                                    true         ReplicaSet
statefulsets                              sts                 apps/v1                                    true         StatefulSet
tokenreviews                                                  authentication.k8s.io/v1                   false        TokenReview
localsubjectaccessreviews                                     authorization.k8s.io/v1                    true         LocalSubjectAccessReview
selfsubjectaccessreviews                                      authorization.k8s.io/v1                    false        SelfSubjectAccessReview
selfsubjectrulesreviews                                       authorization.k8s.io/v1                    false        SelfSubjectRulesReview
subjectaccessreviews                                          authorization.k8s.io/v1                    false        SubjectAccessReview
horizontalpodautoscalers                  hpa                 autoscaling/v1                             true         HorizontalPodAutoscaler
cronjobs                                  cj                  batch/v1                                   true         CronJob
jobs                                                          batch/v1                                   true         Job
sealedsecrets                                                 bitnami.com/v1alpha1                       true         SealedSecret

certificatesigningrequests                csr                 certificates.k8s.io/v1                     false        CertificateSigningRequest
ciliumclusterwidenetworkpolicies          ccnp                cilium.io/v2                               false        CiliumClusterwideNetworkPolicy
ciliumegressgatewaypolicies               cegp                cilium.io/v2                               false        CiliumEgressGatewayPolicy
ciliumegressnatpolicies                                       cilium.io/v2alpha1                         false        CiliumEgressNATPolicy
ciliumendpoints                           cep,ciliumep        cilium.io/v2                               true         CiliumEndpoint
ciliumexternalworkloads                   cew                 cilium.io/v2                               false        CiliumExternalWorkload
ciliumidentities                          ciliumid            cilium.io/v2                               false        CiliumIdentity
ciliumlocalredirectpolicies               clrp                cilium.io/v2                               true         CiliumLocalRedirectPolicy
ciliumnetworkpolicies                     cnp,ciliumnp        cilium.io/v2                               true         CiliumNetworkPolicy
ciliumnodes                               cn,ciliumn          cilium.io/v2                               false        CiliumNode
ciliumstaticendpoints                     ciliumsep,csep      cilium.io/v2                               false        CiliumStaticEndpoint

configs                                                       config.gatekeeper.sh/v1alpha1              true         Config
baselinepsp                                                   constraints.gatekeeper.sh/v1beta1          false        BaselinePSP
cmdblacks                                                     constraints.gatekeeper.sh/v1beta1          false        CmdBlacks
hostpathvolumeblacks                                          constraints.gatekeeper.sh/v1beta1          false        HostPathVolumeBlacks
hostpathvolumepodwhites                                       constraints.gatekeeper.sh/v1beta1          false        HostPathVolumePodWhites
imagesigvalidationpolicyrequiredformats                       constraints.gatekeeper.sh/v1beta1          false        ImageSigValidationPolicyRequiredFormats
k8spspallowedusers                                            constraints.gatekeeper.sh/v1beta1          false        K8sPSPAllowedUsers
k8spspallowhostdirvolumeplugin                                constraints.gatekeeper.sh/v1beta1          false        K8sPSPAllowHostDirVolumePlugin
k8spspallowprivilegeescalationcontainer                       constraints.gatekeeper.sh/v1beta1          false        K8sPSPAllowPrivilegeEscalationContainer
k8spspcapabilities                                            constraints.gatekeeper.sh/v1beta1          false        K8sPSPCapabilities
k8spspflexvolumes                                             constraints.gatekeeper.sh/v1beta1          false        K8sPSPFlexVolumes
k8spsphostfilesystem                                          constraints.gatekeeper.sh/v1beta1          false        K8sPSPHostFilesystem
k8spsphostnamespace                                           constraints.gatekeeper.sh/v1beta1          false        K8sPSPHostNamespace
k8spsphostnetworkingports                                     constraints.gatekeeper.sh/v1beta1          false        K8sPSPHostNetworkingPorts
k8spspprivilegedcontainer                                     constraints.gatekeeper.sh/v1beta1          false        K8sPSPPrivilegedContainer
k8spspreadonlyrootfilesystem                                  constraints.gatekeeper.sh/v1beta1          false        K8sPSPReadOnlyRootFilesystem
k8spspseccomp                                                 constraints.gatekeeper.sh/v1beta1          false        K8sPSPSeccomp
k8spspselinuxv2                                               constraints.gatekeeper.sh/v1beta1          false        K8sPSPSELinuxV2
k8spspsysctls                                                 constraints.gatekeeper.sh/v1beta1          false        K8sPSPSysctls
k8spspvolumetypes                                             constraints.gatekeeper.sh/v1beta1          false        K8sPSPVolumeTypes
publickeyrequiredformats                                      constraints.gatekeeper.sh/v1beta1          false        PublicKeyRequiredFormats
leases                                                        coordination.k8s.io/v1                     true         Lease
desiredversions                                               desiredversion.xlb.io/v1                   true         Desiredversion
endpointslices                                                discovery.k8s.io/v1                        true         EndpointSlice

events                                    ev                  events.k8s.io/v1beta1                      true         Event
providers                                                     externaldata.gatekeeper.sh/v1alpha1        false        Provider
flowschemas                                                   flowcontrol.apiserver.k8s.io/v1beta1       false        FlowSchema
prioritylevelconfigurations                                   flowcontrol.apiserver.k8s.io/v1beta1       false        PriorityLevelConfiguration
asmreleases                               ars                 helm.asm.openpalette/v1                    true         AsmRelease
infrainterfaces                                               infranet.openpallete.io/v1                 true         InfraInterface
infranetworks                                                 infranet.openpallete.io/v1                 true         InfraNetwork
infraphysnets                                                 infranet.openpallete.io/v1                 true         InfraPhysnet
infrasubnets                                                  infranet.openpallete.io/v1                 true         InfraSubnet
iplabels                                                      iplabel.xlb.io/v1                          true         Iplabel
multinetworkpolicies                      multinetpol         k8s.cni.cncf.io/v1                         true         MultiNetworkPolicy
network-attachment-definitions            net-attach-def      k8s.cni.cncf.io/v1                         true         NetworkAttachmentDefinition
nsnetworks                                nsnetwork           k8s.cni.cncf.io/v1                         true         NsNetwork
kubeallbatchreleases                      kbr                 kubeall.io/v1                              true         KubeallBatchRelease
kubeallchartreleases                      kcr                 kubeall.io/v1                              true         KubeallChartRelease
kubeallnodelcms                           knl                 kubeall.io/v1                              true         KubeallNodeLcm
kubeallvirtualips                         kvi                 kubeall.io/v1                              true         KubeallVirtualIp

gatewaygroups                             gwg                 network.knitter.io/v1                      true         GatewayGroup
ipgroups                                  ipg                 network.knitter.io/v1                      true         IPGroup
knitterendpoints                          knitterep           network.knitter.io/v1                      true         KnitterEndpoint
knitteridentities                         knitterid           network.knitter.io/v1                      false        KnitterIdentity
knitternodes                              kn,knittern         network.knitter.io/v1                      false        KnitterNode
networkaccesscontrols                     nac                 network.knitter.io/v1                      false        NetworkAccessControl
networks                                  net                 network.knitter.io/v1                      true         Network
nodenetworkdeviceconfigs                  deviceconfig        network.knitter.io/v1                      false        NodeNetworkDeviceConfig
nodephysnetmappingpolicies                mappingpolicy       network.knitter.io/v1                      false        NodePhysnetMappingPolicy
physicalnetworks                          physnet             network.knitter.io/v1                      false        PhysicalNetwork
trunknetworks                             trunknet            network.knitter.io/v1                      true         TrunkNetwork
ingressclasses                                                networking.k8s.io/v1                       false        IngressClass
ingresses                                 ing                 networking.k8s.io/v1                       true         Ingress
networkpolicies                           netpol              networking.k8s.io/v1                       true         NetworkPolicy
runtimeclasses                                                node.k8s.io/v1                             false        RuntimeClass

openpaletteinfradiskpartitions                                openpalette.openpalette/v1                 true         OpenPaletteInfraDiskPartition
openpaletteinfradisks                                         openpalette.openpalette/v1                 true         OpenPaletteInfraDisk
openpaletteinfranodeinterfaces                                openpalette.openpalette/v1                 true         OpenPaletteInfraNodeInterface
openpaletteinfranodepools                                     openpalette.openpalette/v1                 true         OpenPaletteInfraNodepool
openpaletteinfranodes                                         openpalette.openpalette/v1                 true         OpenPaletteInfraNode
openpaletteinfranodevcpus                                     openpalette.openpalette/v1                 true         OpenPaletteInfraNodeVcpu
openpaletteinfraregions                                       openpalette.openpalette/v1                 true         OpenPaletteInfraRegion
openpaletteinfravips                                          openpalette.openpalette/v1                 true         OpenPaletteInfraVip
poddisruptionbudgets                      pdb                 policy/v1                                  true         PodDisruptionBudget
podsecuritypolicies                       psp                 policy/v1beta1                             false        PodSecurityPolicy
gateways                                                      raven.openyurt.io/v1alpha1                 false        Gateway
clusterrolebindings                                           rbac.authorization.k8s.io/v1               false        ClusterRoleBinding
clusterroles                                                  rbac.authorization.k8s.io/v1               false        ClusterRole
rolebindings                                                  rbac.authorization.k8s.io/v1               true         RoleBinding
roles                                                         rbac.authorization.k8s.io/v1               true         Role
priorityclasses                           pc                  scheduling.k8s.io/v1                       false        PriorityClass
constraintpodstatuses                                         status.gatekeeper.sh/v1beta1               true         ConstraintPodStatus
constrainttemplatepodstatuses                                 status.gatekeeper.sh/v1beta1               true         ConstraintTemplatePodStatus
mutatorpodstatuses                                            status.gatekeeper.sh/v1beta1               true         MutatorPodStatus
csidrivers                                                    storage.k8s.io/v1                          false        CSIDriver
csinodes                                                      storage.k8s.io/v1                          false        CSINode
csistoragecapacities                                          storage.k8s.io/v1beta1                     true         CSIStorageCapacity
storageclasses                            sc                  storage.k8s.io/v1                          false        StorageClass
volumeattachments                                             storage.k8s.io/v1                          false        VolumeAttachment
constrainttemplates                                           templates.gatekeeper.sh/v1                 false        ConstraintTemplate
noderesourcetopologies                    node-res-topo       topology.node.k8s.io/v1alpha2              false        NodeResourceTopology
openpaletteinfradiskanddiskpartitions                         volume-manager.cinder-csi-driver/v1        true         OpenPaletteInfraDiskAndDiskPartition
volumeconnectors                                              volume-manager.cinder-csi-driver/v1        true         VolumeConnector
volumegroups                                                  volume-manager.cinder-csi-driver/v1        true         VolumeGroup
volumes                                                       volume-manager.cinder-csi-driver/v1        true         Volume
volumetargets                                                 volume-manager.cinder-csi-driver/v1        true         VolumeTarget


参考

k8s资源对象及API群组

Logo

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

更多推荐