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?
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:
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.
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.