1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/documentation/kyverno-cli.md

61 lines
1.8 KiB
Markdown
Raw Normal View History

2020-02-17 04:50:02 +00:00
<small>*[documentation](/README.md#documentation) / kyverno-cli*</small>
2020-02-20 02:50:03 +00:00
# Kyverno CLI
2020-02-19 16:17:15 +00:00
The Kyverno Command Line Interface (CLI) is designed to validate policies and test the behavior of applying policies to resources before adding the policy to a cluster. It can be used as a kubectl plugin and as a standalone CLI.
2020-02-17 04:50:02 +00:00
2020-02-20 03:13:05 +00:00
## Build the CLI
2020-02-20 02:50:03 +00:00
2020-02-20 03:24:11 +00:00
You can build the CLI binary locally, then move the binary into a directory in your PATH.
2020-02-20 03:13:05 +00:00
```bash
git clone https://github.com/nirmata/kyverno.git
cd github.com/nirmata/kyverno
make cli
2020-02-20 03:24:55 +00:00
mv ./cmd/cli/kubectl-kyverno/kyverno /usr/local/bin/kyverno
2020-02-20 03:13:05 +00:00
```
2020-02-17 04:50:02 +00:00
## Commands
#### Version
2020-02-20 02:50:03 +00:00
2020-02-17 04:50:02 +00:00
Prints the version of kyverno used by the CLI.
Example:
```
2020-02-20 02:50:03 +00:00
kyverno version
2020-02-17 04:50:02 +00:00
```
#### Validate
2020-02-17 05:05:33 +00:00
Validates a policy, can validate multiple policy resource description files or even an entire folder containing policy resource description
files. Currently supports files with resource description in yaml.
2020-02-17 04:50:02 +00:00
Example:
```
2020-02-20 02:50:03 +00:00
kyverno validate /path/to/policy1.yaml /path/to/policy2.yaml /path/to/folderFullOfPolicies
2020-02-17 04:50:02 +00:00
```
#### Apply
2020-02-19 16:17:15 +00:00
Applies policies on resources, and supports applying multiple policies on multiple resources in a single command.
Also supports applying the given policies to an entire cluster. The current kubectl context will be used to access the cluster.
Will return results to stdout.
2020-02-17 04:50:02 +00:00
Apply to a resource:
```
2020-02-20 02:50:03 +00:00
kyverno apply /path/to/policy.yaml --resource /path/to/resource.yaml
2020-02-17 04:50:02 +00:00
```
2020-02-20 02:50:03 +00:00
2020-02-19 16:17:15 +00:00
Apply to all matching resources in a cluster:
2020-02-17 04:50:02 +00:00
```
2020-02-20 02:50:03 +00:00
kyverno apply /path/to/policy.yaml --cluster > policy-results.txt
2020-02-17 04:50:02 +00:00
```
2020-02-20 02:50:03 +00:00
Apply multiple policies to multiple resources:
2020-02-17 04:50:02 +00:00
```
2020-02-20 02:50:03 +00:00
kyverno apply /path/to/policy1.yaml /path/to/folderFullOfPolicies --resource /path/to/resource1.yaml --resource /path/to/resource2.yaml --cluster
2020-02-17 04:50:02 +00:00
```
2020-02-20 02:50:03 +00:00
<small>*Read Next >> [Sample Policies](/samples/README.md)*</small>