Hi guys, question. i want to create deployment with replicas and i use the hybri . . .

Jacob:
Hi guys, question.
i want to create deployment with replicas and i use the hybrid way meaning imperative command and then adding the replicas in the yaml by editing the yaml.
What is the difference when running imperative command with -o yaml > example.yaml and without the -o yaml and straight to the yaml file.
another thing, in case of imperative command when creating deployment, no option to add the --replicas flag in the command?

Mohamed Ayman:
You can use this command kubectl create deployment <deployment name> --image <image name> and generate the yaml file using this command kubectl get deployments < deployment name> -o yaml > > <file name> then modify the replicas and apply the changes using this command kubectl apply -f <file name>. or try to edit it using this kubectl edit deployment <deployment name> And if you use the imperative method you can add the --replicas flag in the command like this
kubectl create deployment <deployment name> --image <image name> --replicas or try this kubectl create deployment <deployment name> --image <image name> --replicas && kubectl scale deployment <deployment name> --replicas but in this command, the scaling is controlled separately.

Jacob:
thanks for the comment @Mohamed Ayman. still, this is not explains what is the difference between creating deployment straight to yaml file or adding -o yaml to the command.
in other words, what is the difference between these commands
k create deployment <deployment_name> --image=someimage -o yaml > example.yaml
and
k create deployment <deployment_name> --image=someimage > example.yaml

Shwetha Shenoy:
@Jacob The first command with -o yaml creates the deployment and also outputs the resource in yaml format into the example.yaml If you check the example.yaml, it will be of this format.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx

The second command writes the output of the execution into the example.yaml
If you cat the example.yaml file, it will how something like below.

deployment.apps/nginx created

Shwetha Shenoy:
Since, in both of theses commands you didnt mention --dry-run=client, the resource is created in the cluster. If you intend to just write it in the file and not actually create it, dont forget the --dry-run=client flag. :slightly_smiling_face:

Jacob:
@Shwetha Shenoy right, im aware of the dry run, thanks :slightly_smiling_face:
so you saying there is no difference when creating deployment with -o yaml and without it when creating direct to some yaml file?

Shwetha Shenoy:
Well, in the second case, you dont get the yaml file for the deployment. You just know thtat it was created. In the first case, you also get the yaml output from the deployment

Ayush Jain:
@Jacob, yes. No difference while creating deployment with or without -o yaml. The same deployment will be created in both commands.

Shwetha Shenoy:
Apart from the outputs, there is no difference

Jacob:
thank you guys :thumbsup: