Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are generators in kubernetes kubectl?

When I want to generate yaml by running kubectl, it denotes that I should denote --generator=something flag within the command.

For example, to get the deployment template via kubectl, I should run the below command:

kubectl run --generator=deployment/v1beta1 nginx --image=nginx --dry-run -o yaml

Without mentioning --generator flag the CLI states in some kind that I should mention the generator flag with a proper value (e.g. run-pod/v1).

My question is, what is essentially a generator? What does it do? Are they some sort of object creation templates or something else?

like image 213
Farshid Avatar asked May 04 '19 11:05

Farshid


People also ask

What is -- dry-run in kubectl?

Kubectl apply dry-run does the necessary work by producing the outcome of the apply merge deprived of actually maintaining it. Perhaps we upgrade flag help, issue a notice if Dry-run is used when appraising items using Apply, document Dry-run's limits, and use server dry-run.

What is the difference between kubectl run and create?

The key difference between kubectl apply and create is that apply creates Kubernetes objects through a declarative syntax, while the create command is imperative. The command set kubectl apply is used at a terminal's command-line window to create or modify Kubernetes resources defined in a manifest file.

What is kubectl rollout?

You can use kubectl rollout to inspect a rollout as it occurs, to pause and resume a rollout, to rollback an update, and to view an object's rollout history.

What is flag in Kubernetes?

flags : Specifies optional flags. For example, you can use the -s or --server flags to specify the address and port of the Kubernetes API server. Important: Flags that you specify from the command line override default values and any corresponding environment variables.


1 Answers

That was introduced in commit 426ef93, Jan. 2016 for Kubernetes v1.2.0-alpha.8.

The generators were described as:

Generators are kubectl commands that generate resources based on a set of inputs (other resources, flags, or a combination of both).

The point of generators is:

  • to enable users using kubectl in a scripted fashion to pin to a particular behavior which may change in the future.
    Explicit use of a generator will always guarantee that the expected behavior stays the same.
  • to enable potential expansion of the generated resources for scenarios other than just creation, similar to how -f is supported for most general-purpose commands.

And:

Generator commands should obey to the following conventions:

  • A --generator flag should be defined. Users then can choose between different generators, if the command supports them (for example, kubectl run currently supports generators for pods, jobs, replication controllers, and deployments), or between different versions of a generator so that users depending on a specific behavior may pin to that version (for example, kubectl expose currently supports two different versions of a service generator).
  • Generation should be decoupled from creation.
    A generator should implement the kubectl.StructuredGenerator interface and have no dependencies on cobra or the Factory
like image 176
VonC Avatar answered Sep 17 '22 12:09

VonC