Container Orchestration
medium

Questão de Container Orchestration #019e3a4f

Enunciado da Questão
Container Orchestration
#kubernetes
#kubectl
#deployment
#replicas
Médio

Which of the following is the correct command to run a nginx deployment with 2 replicas?

A

kubectl run deploy nginx --image=nginx --replicas=2

B

kubectl create deploy nginx --image=nginx --replicas=2

Correta
C

kubectl create nginx deployment --image=nginx –replicas=2

D

kubectl create deploy nginx --image=nginx --count=2

Explicação Oficial / Explicações da Comunidade

The correct command to create a Kubernetes Deployment with 2 replicas is kubectl create deploy nginx --image=nginx --replicas=2. This uses the kubectl create deployment subcommand (abbreviated as deploy) to create a Deployment named nginx with the specified container image and replica count.

How it Works

  • kubectl create deployment is the standard command to create a Deployment resource in Kubernetes.
  • The --image flag specifies the container image to use for the pods.
  • The --replicas flag sets the desired number of pod replicas.
  • The Deployment controller ensures that the specified number of pods are running and handles updates and rollbacks.

Why Other Options Are Incorrect

  • kubectl run deploy nginx --image=nginx --replicas=2: The kubectl run command is used to create a single pod or a deployment, but its syntax for creating a deployment is kubectl run <name> --image=<image>. The --replicas flag is not valid for kubectl run; it only creates a single pod by default. Additionally, the word deploy in the command is misinterpreted as the pod name, not a subcommand.
  • kubectl create nginx deployment --image=nginx –replicas=2: This command has incorrect argument order. The correct syntax is kubectl create deployment <name> --image=<image>. Placing the name after create and before deployment is invalid.
  • kubectl create deploy nginx --image=nginx --count=2: The --count flag is not a valid flag for kubectl create deployment. The correct flag is --replicas. Using --count will result in an error or be ignored.