calicoctl apply

This sections describes the calicoctl apply command.

Read the calicoctl command line interface user reference for a full list of calicoctl commands.

calicoctl apply - 图1note

The available actions for a specific resource type may be limited based on the datastore used for Calico (etcdv3 / Kubernetes API). Please refer to the Resources section for details about each resource type.

Displaying the help text for ‘calicoctl apply’ command

Run calicoctl apply --help to display the following help menu for the command.

  1. Usage:
  2. calicoctl apply --filename=<FILENAME> [--recursive] [--skip-empty] [--config=<CONFIG>] [--namespace=<NS>]
  3. Examples:
  4. # Apply a policy using the data in policy.yaml.
  5. calicoctl apply -f ./policy.yaml
  6. # Apply a policy based on the JSON passed into stdin.
  7. cat policy.json | calicoctl apply -f -
  8. Options:
  9. -h --help Show this screen.
  10. -f --filename=<FILENAME> Filename to use to apply the resource. If set to
  11. "-" loads from stdin. If filename is a directory, this command is
  12. invoked for each .json .yaml and .yml file within that directory,
  13. terminating after the first failure.
  14. -R --recursive Process the filename specified in -f or --filename recursively.
  15. --skip-empty Do not error if any files or directory specified using -f or --filename contain no
  16. data.
  17. -c --config=<CONFIG> Path to the file containing connection
  18. configuration in YAML or JSON format.
  19. [default: /etc/calico/calicoctl.cfg]
  20. -n --namespace=<NS> Namespace of the resource.
  21. Only applicable to NetworkPolicy and WorkloadEndpoint.
  22. Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.
  23. Uses the default namespace if not specified.
  24. --context=<context> The name of the kubeconfig context to use.
  25. Description:
  26. The apply command is used to create or replace a set of resources by filename
  27. or stdin. JSON and YAML formats are accepted.
  28. Valid resource types are:
  29. * bgpConfiguration
  30. * bgpPeer
  31. * felixConfiguration
  32. * globalNetworkPolicy
  33. * hostEndpoint
  34. * ipPool
  35. * networkPolicy
  36. * networkSet
  37. * node
  38. * profile
  39. * workloadEndpoint
  40. When applying a resource:
  41. - if the resource does not already exist (as determined by it's primary
  42. identifiers) then it is created
  43. - if the resource already exists then the specification for that resource is
  44. replaced in it's entirety by the new resource specification.
  45. The output of the command indicates how many resources were successfully
  46. applied, and the error reason if an error occurred.
  47. The resources are applied in the order they are specified. In the event of a
  48. failure applying a specific resource it is possible to work out which
  49. resource failed based on the number of resources successfully applied
  50. When applying a resource to perform an update, the complete resource spec
  51. must be provided, it is not sufficient to supply only the fields that are
  52. being updated.

Examples

  1. Apply a set of resources (of mixed type) using the data in resources.yaml.

    1. calicoctl apply -f ./resources.yaml

    Results indicate that 8 resources were successfully applied

    1. Successfully applied 8 resource(s)
  2. Apply two policy resources based on the JSON passed into stdin.

    1. cat policy.json | calicoctl apply -f -

    Results indicate success.

    1. Successfully applied 2 'policy' resource(s)

Options

  1. -f --filename=<FILENAME> Filename to use to apply the resource. If set to
  2. "-" loads from stdin.
  3. -n --namespace=<NS> Namespace of the resource.
  4. Only applicable to NetworkPolicy and WorkloadEndpoint.
  5. Uses the default namespace if not specified.

General options

  1. -c --config=<CONFIG> Path to the file containing connection
  2. configuration in YAML or JSON format.
  3. [default: /etc/calico/calicoctl.cfg]

See also