此 yaml 的等效 kubectl 命令是什么?

What are the equivelant kubectl commands to this yaml?

我正在尝试创建 Role 和 RoleBinding 以便我可以使用 Helm。创建以下资源的等效 kubectl 命令是什么?在我的场景中使用命令行使开发操作更简单。

角色

kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-manager-foo
  namespace: foo
rules:
- apiGroups: ["", "batch", "extensions", "apps"]
  resources: ["*"]
  verbs: ["*"]

角色绑定

kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-binding-foo
  namespace: foo
subjects:
- kind: ServiceAccount
  name: tiller-foo
  namespace: foo
roleRef:
  kind: Role
  name: tiller-manager-foo
  apiGroup: rbac.authorization.k8s.io

更新

根据@nightfury1204,我可以运行创建以下Role

kubectl create role tiller-manager-foo --namespace foo --verb=* --resource=.,.apps,.batch, .extensions -n foo --dry-run -o yaml

这输出:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  creationTimestamp: null
  name: tiller-manager-foo
rules:
- apiGroups:
  - ""
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - apps
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - batch
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - extensions
  resources:
  - '*'
  verbs:
  - '*'

namespace 缺失,其次,这是等效的吗?

角色:

kubectl  create role tiller-manager-foo --verb=* --resource=*.batch,*.extensions,*.apps,*. -n foo

--resource=* support added on kubectl 1.12 version

对于角色绑定:

kubectl create rolebinding tiller-binding-foo --role=tiller-manager-foo --serviceaccount=foo:tiller-foo -n foo

kubectl apply -f 可以像问题中那样提交任意 Kubernetes YAML 文件。

我在这里特别建议这样做,因为您可以将这些 YAML 文件提交到源代码管理,如果您仍然使用 Helm,那么这远不是您拥有的唯一 Kubernetes YAML 文件。这为您甚至 bootstrap 您的 Helm 设置提供了一致的路径。