kubectl imperative object configuration use case

10/3/2019

Out of the Kubernetes docs a kubectl tool has "three kinds of object management":

  • imperative commands
  • imperative object configuration
  • declarative object configuration

While the first and the last options' use cases are more or less clear, the second one really makes me confusing.

Moreover in the concepts section there is a clear distinction of use cases:

  • use imperative commands for quick creation of (simple) single-container resources
  • use declarative commands for managing (more complex) set of resources

Also imperative style is recommended for CKA certification so it seems to be preferred for day-to-day cluster management activities.

But once again what is a best use case / practice for "Imperative object configuration" option and what is the root idea behind it?

-- esboych
kubectl
kubernetes

1 Answer

10/8/2019

There are two basic ways to deploy to Kubernetes: imperatively, with kubectl commands, or declaratively, by writing manifests and using kubectl apply. A Kubernetes object should be managed using only one technique. It is better to use only one way for the same object, mixing techniques for the same object results in undefined behavior.

  • Imperative commands operates on live objects
  • Imperative object configuration operates on individual files
  • Declarative object configuration operates on directories of files

Imperative object configuration creates, updates and deletes objects using configuration files, which contains fully-defined object definitions. You can store object configuration files in source control systems and audit changes more easily than with imperative commands.

You can run kubectl apply, delete, and replace operations with configuration files or directories containing configuration files.

Please refer to official documentation, where everything is fully described with examples. I hope it is helpful.

-- muscat
Source: StackOverflow