k8s中的哪个API组

Which API Group in k8s

如何确定任何给定资源属于哪个apiGroup

kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  namespace: default
  name: thing
rules:
- apiGroups: ["<wtf goes here>"]
  resources: ["deployments"]
  verbs: ["get", "list"]
  resourceNames: []

kubectl api-resources -o wide 在系统上提供支持的 API 资源。

[suresh.vishnoi@xxx1309 ~]$ kubectl api-resources -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]
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]

kubectl api-resources -o wide | grep -i deployment会提供相关资料

apps 是部署资源的 apiGroup

DaemonSet, Deployment, StatefulSet, and ReplicaSet: will no longer be served from extensions/v1beta1, apps/v1beta1, or apps/v1beta2 in v1.16. Migrate to the apps/v1 API, available since v1.9. Existing persisted data can be retrieved/updated via the apps/v1 API./api-deprecations-in-1-16

在线收录API documentation

在您的示例中,如果您单击并发现 Role, it lists the group and version in both the sidebar ("Role v1 rbac.authorization.k8s.io") and as the first line in the actual API documentation. Similarly, Deployment 的文档位于组 "apps" 中,版本为 "v1"。

在 RBAC 文档的 Role specification you only put the group, and it applies to all versions. So to control access to Deployments, you'd specify apiGroups: [apps], resources: [deployments]. (This is actually one of the examples 中。)

这有点棘手,因为最近的 kubernetes 版本中都在使用组应用程序和扩展程序,例如
kubectl get deployments # 默认情况下仍然通过扩展 api 组请求。
kubectl get deployments.apps # 通过应用组请求

因此,在从扩展 api 组中删除部署之前,您必须在您的角色中使用这两个 api 组。

  • api群组:["apps","extensions"]

https://github.com/kubernetes/kubernetes/issues/67439

您可以运行下面的命令来获取 apiVersion 和其他详细信息。

 kubectl explain <Resource Name>
 kubectl explain deployment

获取 API 资源 - 由您的 Kubernetes 集群支持:

 kubectl api-resources -o wide

example:
NAME                              SHORTNAMES   APIGROUP                       NAMESPACED   KIND                             VERBS
deployments                       deploy       apps                           true         Deployment                   [create delete deletecollection get list patch update watch]
deployments                       deploy       extensions                     true         Deployment                   [create delete deletecollection get list patch update watch]

要获取 API 版本 - 您的 Kubernetes 集群支持:

kubectl api-versions

你可以验证f.e。部署:

kubectl explain deploy 

KIND:     Deployment
VERSION:  extensions/v1beta1

DESCRIPTION:
     DEPRECATED - This group version of Deployment is deprecated by
     apps/v1beta2/Deployment.

此外,您可以使用 api-version:

进行调查
kubectl explain deploy --api-version apps/v1

很快你会在你的api组中指定:

apiGroups: ["extensions", "apps"]

您还可以为您的集群配置这些设置(例如测试它将与下一个 1.16 release) by passing options into --runtime-config in kube-apiserver 一起使用)。

其他资源:

在以后的k8s版本中,apigroup被弃用,指令kubectl api-resources -o wide会显示apiversion,它是apigroup/version

的组合