What is the recommended alternative to kubectl '--generator' option?

8/26/2019

One of the points in the kubectl best practices section in Kubernetes Docs state below:

Pin to a specific generator version, such as kubectl run --generator=deployment/v1beta1

But then a little down in the doc, we get to learn that except for Pod, the use of --generator option is deprecated and that it would be removed in future versions.

Why is this being done? Doesn't generator make life easier in creating a template file for resource definition of deployment, service, and other resources? What alternative is the kubernetes team suggesting? This isn't there in the docs :(

-- karthiks
kubectl
kubernetes

2 Answers

8/26/2019

kubectl create is the recommended alternative if you want to use more than just a pod (like deployment).

https://kubernetes.io/docs/reference/kubectl/conventions/#generators says:

Note: kubectl run --generator except for run-pod/v1 is deprecated in v1.12.

This pull request has the reason why generators (except run-pod/v1) were deprecated:

The direction is that we want to move away from kubectl run because it's over bloated and complicated for both users and developers. We want to mimic docker run with kubectl run so that it only creates a pod, and if you're interested in other resources kubectl create is the intended replacement.

-- Vikram Hosakote
Source: StackOverflow

8/26/2019

For deployment you can try

kubectl create deployment hello-node --image=gcr.io/hello-minikube-zero-install/hello-node

and

Note: kubectl run --generator except for run-pod/v1 is deprecated in v1.12.

-- Bimal
Source: StackOverflow