Create a deployment with 2 pods with one command

Hello,

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 :

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

Thanks

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:

https://github.com/kubernetes/kubernetes/commit/b6213ed931930eba27b4a53db54b4b4d224a1c59#diff-2d8740727a0dc319084ab9123b72db30d131aaf04f9f3095d534a98bd7632638

1 Like