# kubectl create role 命令详解
使用单一规则创建 Role。
# 语法
$ role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run]
# 示例
创建名为“pod-reader”的 Role,允许用户在 pod 上执行“get”,“watch”和“list”
kubectl create role pod-reader --verb=get --verb=list --verb=watch --resource=pods
创建名为“pod-reader”的 Role,并指定 ResourceName
kubectl create role pod-reader --verb=get,list,watch --resource=pods --resource-name=readablepod --resource-name=anotherpod
使用指定的 API Group 创建名为“foo”的 Role
kubectl create role foo --verb=get,list,watch --resource=rs.extensions
使用指定的 SubResource 创建名为“foo”的 Role
kubectl create role foo --verb=get,list,watch --resource=pods,pods/status
# Flags
Name | Shorthand | Default | Usage |
---|---|---|---|
allow-missing-template-keys | true | If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. | |
dry-run | false | If true, only print the object that would be sent, without sending it. | |
no-headers | false | When using the default or custom-column output format, don't print headers (default print headers). | |
output | o | Output format. One of: json|yaml|wide|name|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See custom columns [http://kubernetes.io/docs/user-guide/kubectl-overview/#custom-columns], golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://kubernetes.io/docs/user-guide/jsonpath]. | |
output-version | DEPRECATED: To use a specific API version, fully-qualify the resource, version, and group (for example: 'jobs.v1.batch/myjob'). | ||
resource | [] | resource that the rule applies to | |
resource-name | [] | resource in the white list that the rule applies to, repeat this flag for multiple items | |
save-config | false | If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future. | |
schema-cache-dir | ~/.kube/schema | If non-empty, load/store cached API schemas in this directory, default is '$HOME/.kube/schema' | |
show-all | a | false | When printing, show all resources (default hide terminated pods.) |
show-labels | false | When printing, show all labels as the last column (default hide labels column) | |
sort-by | If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. '{.metadata.name}'). The field in the API resource specified by this JSONPath expression must be an integer or a string. | ||
template | Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. | ||
validate | true | If true, use a schema to validate the input before sending it | |
verb | [] | verb that applies to the resources contained in the rule |