如何确定 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: []
如何确定 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: []
要获取 Kubernetes 集群支持的 API 资源:
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]
获取 Kubernetes 集群支持的 API 版本:
kubectl api-versions
您可以验证 fe 部署:
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
很快,您将在 apiGroups 中指定,例如:
apiGroups: ["extensions", "apps"]
您还可以通过将选项传递给kube-apiserver 来为您的集群配置这些设置(例如,测试它将与下一个1.16 版本一起使用) 。--runtime-config
其他资源:
特定版本的其他值得注意的功能更新 如下:
Continued deprecation of extensions/v1beta1, apps/v1beta1, and apps/v1beta2 APIs; these extensions will be retired in 1.16!
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 和 ReplicaSet:在 v1.16 中将不再从 extensions/v1beta1、apps/v1beta1 或 apps/v1beta2 提供服务。迁移到应用程序/v1 API,从 v1.9 开始可用。可以通过 apps/v1 API 检索/更新现有的持久数据。/api-deprecations-in-1-16
这有点棘手,因为在最近的 kubernetes 版本中都使用了组应用程序和扩展,例如
kubectl get deployments # 默认情况下仍然通过扩展 api 组请求它。
kubectl get deployments.apps # 通过应用组请求
因此,在从扩展 apigroup 中删除部署之前,您必须在角色中使用这两个 apigroup。
您可以运行以下命令以获取 apiVersion 和其他详细信息。
kubectl explain <Resource Name>
kubectl explain deployment