0

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
  • 441
  • 5
  • 14
  • It's almost always better to write a YAML file for, say, a deployment, check it into source control, and install it using `kubectl apply`; try to avoid `kubectl run` except for one-off debugging pods. That having been said, this output sort of looks like your cluster is broken, and fixing that isn't the sort of programming question that SO focuses on. – David Maze Dec 02 '19 at 01:15
  • @DavidMaze Thanks for the advice! However, k8s tutorial says readers to do so(`kubectl run`), thus it's weird the error occurs. – jjangga Dec 02 '19 at 05:56
  • 1
    That's strange. What's your kubernetes version? I would say your `kubectl` is newer version then your kubernetes cluster, so on your cluster, it is still expecting to dun deployments as `deployment/v1beta1`, but `kubectl` is trying to create the deployment with the promoted `deployment/apps.v1` `apiVersion`. – suren Dec 02 '19 at 08:38

2 Answers2

0

Try

kubectl create deployment --image nginx my-nginx
yasin lachini
  • 5,188
  • 6
  • 33
  • 56
0

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

Vit
  • 7,740
  • 15
  • 40