1. [root@master ~]# kubectl create --help
    2. Create a resource from a file or from stdin.
    3. JSON and YAML formats are accepted.
    4. Examples:
    5. # Create a pod using the data in pod.json.
    6. kubectl create -f ./pod.json
    7. # Create a pod based on the JSON passed into stdin.
    8. cat pod.json | kubectl create -f -
    9. # Edit the data in docker-registry.yaml in JSON then create the resource using the edited data.
    10. kubectl create -f docker-registry.yaml --edit -o json
    11. Available Commands:
    12. clusterrole Create a ClusterRole.
    13. clusterrolebinding Create a ClusterRoleBinding for a particular ClusterRole
    14. configmap Create a configmap from a local file, directory or literal value
    15. cronjob Create a cronjob with the specified name.
    16. deployment Create a deployment with the specified name.
    17. job Create a job with the specified name.
    18. namespace Create a namespace with the specified name
    19. poddisruptionbudget Create a pod disruption budget with the specified name.
    20. priorityclass Create a priorityclass with the specified name.
    21. quota Create a quota with the specified name.
    22. role Create a role with single rule.
    23. rolebinding Create a RoleBinding for a particular Role or ClusterRole
    24. secret Create a secret using specified subcommand
    25. service Create a service using specified subcommand.
    26. serviceaccount Create a service account with the specified name
    27. Options:
    28. --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in
    29. the template. Only applies to golang and jsonpath output formats.
    30. --dry-run='none': Must be "none", "server", or "client". If client strategy, only print the object that would be
    31. sent, without sending it. If server strategy, submit server-side request without persisting the resource.
    32. --edit=false: Edit the API resource before creating
    33. -f, --filename=[]: Filename, directory, or URL to files to use to create the resource
    34. -k, --kustomize='': Process the kustomization directory. This flag can't be used together with -f or -R.
    35. -o, --output='': Output format. One of:
    36. json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
    37. --raw='': Raw URI to POST to the server. Uses the transport specified by the kubeconfig file.
    38. --record=false: Record current kubectl command in the resource annotation. If set to false, do not record the
    39. command. If set to true, record the command. If not set, default to updating the existing annotation value only if one
    40. already exists.
    41. -R, --recursive=false: Process the directory used in -f, --filename recursively. Useful when you want to manage
    42. related manifests organized within the same directory.
    43. --save-config=false: If true, the configuration of current object will be saved in its annotation. Otherwise, the
    44. annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
    45. -l, --selector='': Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)
    46. --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The
    47. template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
    48. --validate=true: If true, use a schema to validate the input before sending it
    49. --windows-line-endings=false: Only relevant if --edit=true. Defaults to the line ending native to your platform.
    50. Usage:
    51. kubectl create -f FILENAME [options]
    52. Use "kubectl <command> --help" for more information about a given command.
    53. Use "kubectl options" for a list of global command-line options (applies to all commands).
    54. [root@master ~]#
    1. [root@master ~]# kubectl create clusterrole --help
    2. Create a ClusterRole.
    3. Examples:
    4. # Create a ClusterRole named "pod-reader" that allows user to perform "get", "watch" and "list" on pods
    5. kubectl create clusterrole pod-reader --verb=get,list,watch --resource=pods
    6. # Create a ClusterRole named "pod-reader" with ResourceName specified
    7. kubectl create clusterrole pod-reader --verb=get --resource=pods --resource-name=readablepod
    8. --resource-name=anotherpod
    9. # Create a ClusterRole named "foo" with API Group specified
    10. kubectl create clusterrole foo --verb=get,list,watch --resource=rs.extensions
    11. # Create a ClusterRole named "foo" with SubResource specified
    12. kubectl create clusterrole foo --verb=get,list,watch --resource=pods,pods/status
    13. # Create a ClusterRole name "foo" with NonResourceURL specified
    14. kubectl create clusterrole "foo" --verb=get --non-resource-url=/logs/*
    15. # Create a ClusterRole name "monitoring" with AggregationRule specified
    16. kubectl create clusterrole monitoring --aggregation-rule="rbac.example.com/aggregate-to-monitoring=true"
    17. Options:
    18. --aggregation-rule=: An aggregation label selector for combining ClusterRoles.
    19. --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in
    20. the template. Only applies to golang and jsonpath output formats.
    21. --dry-run='none': Must be "none", "server", or "client". If client strategy, only print the object that would be
    22. sent, without sending it. If server strategy, submit server-side request without persisting the resource.
    23. --non-resource-url=[]: A partial url that user should have access to.
    24. -o, --output='': Output format. One of:
    25. json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
    26. --resource=[]: Resource that the rule applies to
    27. --resource-name=[]: Resource in the white list that the rule applies to, repeat this flag for multiple items
    28. --save-config=false: If true, the configuration of current object will be saved in its annotation. Otherwise, the
    29. annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
    30. --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The
    31. template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
    32. --validate=true: If true, use a schema to validate the input before sending it
    33. --verb=[]: Verb that applies to the resources contained in the rule
    34. Usage:
    35. kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename]
    36. [--dry-run=server|client|none] [options]
    37. Use "kubectl options" for a list of global command-line options (applies to all commands).
    38. [root@master ~]#
    1. [root@master ~]# kubectl create namespace app-team1
    2. namespace/app-team1 created
    3. [root@master ~]# kubectl create clusterrole deployment-clusterrole --verb=create --resource=deployments,statefulsets,daemonsets
    4. clusterrole.rbac.authorization.k8s.io/deployment-clusterrole created
    5. [root@master ~]# kubectl create serviceaccount cicd-token --namespace=app-team1
    6. serviceaccount/cicd-token created
    7. [root@master ~]# kubectl create rolebinding deployment-clusterole --clusterrole=deployment=clusterrole --serviceaccount=app-team1:cicd-token --namespace=app-team1
    8. rolebinding.rbac.authorization.k8s.io/deployment-clusterole created
    9. [root@master ~]#
    1. [root@master ~]# kubectl get rolebindings.rbac.authorization.k8s.io -n app-team1
    2. NAME ROLE AGE
    3. deployment-clusterole ClusterRole/deployment=clusterrole 4m50s
    4. [root@master ~]# kubectl describe rolebindings.rbac.authorization.k8s.io -n app-team1
    5. Name: deployment-clusterole
    6. Labels: <none>
    7. Annotations: <none>
    8. Role:
    9. Kind: ClusterRole
    10. Name: deployment=clusterrole
    11. Subjects:
    12. Kind Name Namespace
    13. ---- ---- ---------
    14. ServiceAccount cicd-token app-team1
    15. [root@master ~]# kubectl describe serviceaccounts cicd-token -n app-team1
    16. Name: cicd-token
    17. Namespace: app-team1
    18. Labels: <none>
    19. Annotations: <none>
    20. Image pull secrets: <none>
    21. Mountable secrets: cicd-token-token-jbpjd
    22. Tokens: cicd-token-token-jbpjd
    23. Events: <none>
    24. [root@master ~]#
    25. [root@master ~]# kubectl describe clusterrole deployment-clusterrole -n app-team1
    26. Name: deployment-clusterrole
    27. Labels: <none>
    28. Annotations: <none>
    29. PolicyRule:
    30. Resources Non-Resource URLs Resource Names Verbs
    31. --------- ----------------- -------------- -----
    32. daemonsets.apps [] [] [create]
    33. deployments.apps [] [] [create]
    34. statefulsets.apps [] [] [create]
    35. [root@master ~]#