Manage policies with YAML

Manage policies with YAML

This section describes how to use YAML to manage existing policies in the following ways:

There is also a table of common kubectl commands.

Change which policy manages a workload

To change the policy that manages a workload, edit the policy selectors on the current and the desired policy.

Tip
To avoid an unmanaged gap, add the workload to the new policy before removing it from the old policy.

Stop optimization of a workload

To stop optimizing a workload, remove the workload from policy selection, using the relevant solution:

After removing, the workload may still be managed if it matches a different policy.

Common kubectl commands

Replace the values inside [ ] with your values.

CRDs

Annotations

To do this Use this command
List policies kubectl get [policy-crd]
View a policy manifest kubectl get [policy-crd] [policy-name] -o yaml
Create or update a policy kubectl apply -f [policy-file].yaml
Add or update the workload policy annotation kubectl annotate [workload-kind]/[workload-name] -n [namespace] [policy-annotation-key]=[policy-name] --overwrite
Remove the workload policy annotation kubectl annotate [workload-kind]/[workload-name] -n [namespace] [policy-annotation-key]-
Delete a custom policy kubectl delete [policy-crd] [policy-name]