Why does simple kubectl(1.16) run show an error?

12/1/2019

kubectl version

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-18T14:56:51Z", GoVersion:"go1.12.13", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2", GitCommit:"c97fe5036ef3df2967d086711e6c0c405941e14b", GitTreeState:"clean", BuildDate:"2019-10-15T19:09:08Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}

error When I run kubectl run, an error occurs.

$ kubectl run nginx --image=nginx
WARNING: New generator "deployment/apps.v1" specified, but it isn't available. Falling back to "run/v1".
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
error: no matches for kind "Deployment" in version "apps/v1"

It seems like this is caused by a new version(1.16.x), doesn't it? As far as I searched, even official documents doesn't explicitly mention something related to this situation. How can I use kubectl run?

-- jjangga
kubectl
kubernetes

2 Answers

12/2/2019

Try

kubectl create deployment --image nginx my-nginx
-- yasin lachini
Source: StackOverflow

12/4/2019

As kubectl Usage Conventions suggests,

Specify the --generator flag to pin to a specific behavior when you use generator-based commands such as kubectl run or kubectl expose

Use kubectl run --generator=run-pod/v1 nginnnnnnx --image nginx instead.

Also @soltysh describes well enough why its better to use kubectl create instead of kubectl run

-- VKR
Source: StackOverflow