What are generators in kubernetes kubectl?

旧时模样 提交于 2019-12-22 08:06:15

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/55981949/what-are-generators-in-kubernetes-kubectl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!