Create a deployment with 2 pods with one command


Before, we used the “kubectl run” command to create a deployment with the pods.

Today, how can I use a single command to do that ?
I’m searching, and I only find yaml files to apply.

The old command is :
kubectl run sample-nginx --image=nginx --replicas=2 --port=80

I’m looking for a single command to create a deployment with the 2 pods.

This won’t work :
kubectl create deployment sample-nginx --image=nginx --replicas=2 --port=80

Because, there are no “replicas” flag.
And they don’t even talk about “replicas” in kubectl create --help.

In a deployment yaml file, we can say :

  replicas: 3

This works :

kubectl create deployment sample-nginx --image=nginx
kubectl scale deployment sample-nginx --replicas=2

Is it the good way to do that ?
Is it impossible to add replicas with kubectl create deployment ?


I asked and was informed:

The “–r” or “–replicas” flag was added last May 28th (so I think for 1.19) to kubectl create deployment. It was added in this commit:

1 Like