Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubectl run is deprecated - looking for alternative

I'm using kubectl run with environment parameters to create temporary docker containers for me (e.g. some forwarding for debugging purposes). Since several weeks kubectl is complaining about kubectl run being deprecated. Unfortunately I can't find an appropriate replacement.

This is the old command:

$KUBECTL run -i -t --attach=false --image djfaze/port-forward --env="REMOTE_HOST=$REMOTE_HOST" --env="REMOTE_PORT=$REMOTE_PORT" $POD_NAME 

When issuing this, kubectl complains with this message:

kubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.

Any ideas how to replace this run command?

like image 726
peez80 Avatar asked Oct 19 '18 10:10

peez80


People also ask

What is kubectl Run command?

Kubernetes provides a command line tool for communicating with a Kubernetes cluster's control plane, using the Kubernetes API. This tool is named kubectl . For configuration, kubectl looks for a file named config in the $HOME/. kube directory.

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 happens when I type kubectl run?

After kubectl generates the runtime object, it starts to find the appropriate API group and version for it and then assembles a versioned client that is aware of the various REST semantics for the resource.


1 Answers

As the author of the problem let me explain a little bit the intention behind this deprecation. Just like Brendan explains in his answer, kubectl run per se is not being deprecated, only all the generators, except for the one that creates a Pod for you.

The reason for this change is two folds:

  1. The vast majority of input parameters for kubectl run command is overwhelming for newcomers, as well as for the old timers. It's not that easy to figure out what will be the result of your invocation. You need to take into consideration several passed options as well as the server version.

  2. The code behind it is also a mess to maintain given the matrix of possibilities is growing faster than we can handle.

That's why we're trying to move people away from using kubectl run for their daily workflows and convince them that using explicit kubectl create commands is more straightforward. Finally, we want to make the newcomers that played with docker or any other container engine, where they run a container, to have the same experience with Kubernetes where kubectl run will just run a Pod in a cluster.

Sorry for the initial confusion and I hope this will clear things up.

UPDATE (2020/01/10): As of https://github.com/kubernetes/kubernetes/pull/87077 kubectl run will ONLY create Pods. All generators will be removed entirely.

like image 83
soltysh Avatar answered Sep 20 '22 12:09

soltysh