calicoctl create

This sections describes the calicoctl create command.

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

calicoctl create - 图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 create’ command

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

  1. Usage:
  2. calicoctl create --filename=<FILENAME> [--recursive] [--skip-empty] [--skip-exists] [--config=<CONFIG>] [--namespace=<NS>]
  3. Examples:
  4. # Create a policy using the data in policy.yaml.
  5. calicoctl create -f ./policy.yaml
  6. # Create a policy based on the JSON passed into stdin.
  7. cat policy.json | calicoctl create -f -
  8. Options:
  9. -h --help Show this screen.
  10. -f --filename=<FILENAME> Filename to use to create 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. --skip-exists Skip over and treat as successful any attempts to
  18. create an entry that already exists.
  19. -c --config=<CONFIG> Path to the file containing connection
  20. configuration in YAML or JSON format.
  21. [default: /etc/calico/calicoctl.cfg]
  22. -n --namespace=<NS> Namespace of the resource.
  23. Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.
  24. Uses the default namespace if not specified.
  25. --context=<context> The name of the kubeconfig context to use.
  26. Description:
  27. The create command is used to create a set of resources by filename or stdin.
  28. JSON and YAML formats are accepted.
  29. Valid resource types are:
  30. * bgpConfiguration
  31. * bgpPeer
  32. * felixConfiguration
  33. * globalNetworkPolicy
  34. * hostEndpoint
  35. * ipPool
  36. * networkPolicy
  37. * networkSet
  38. * node
  39. * profile
  40. * workloadEndpoint
  41. Attempting to create a resource that already exists is treated as a
  42. terminating error unless the --skip-exists flag is set. If this flag is set,
  43. resources that already exist are skipped.
  44. The output of the command indicates how many resources were successfully
  45. created, and the error reason if an error occurred. If the --skip-exists
  46. flag is set then skipped resources are included in the success count.
  47. The resources are created in the order they are specified. In the event of a
  48. failure creating a specific resource it is possible to work out which
  49. resource failed based on the number of resources successfully created.

Examples

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

    1. calicoctl create -f ./resources.yaml

    Results indicate that 8 resources were successfully created.

    1. Successfully created 8 resource(s)
  2. Create the same set of resources reading from stdin.

    1. cat resources.yaml | calicoctl create -f -

    Results indicate failure because the first resource (in this case a Profile) already exists.

    1. Failed to create any resources: resource already exists: Profile(name=profile1)

Options

  1. -f --filename=<FILENAME> Filename to use to create the resource. If set to
  2. "-" loads from stdin.
  3. --skip-exists Skip over and treat as successful any attempts to
  4. create an entry that already exists.
  5. -n --namespace=<NS> Namespace of the resource.
  6. Only applicable to NetworkPolicy and WorkloadEndpoint.
  7. 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