Course contentsShow
← Cloud and Infrastructure
Lesson 1135 of 2,98922. Kubernetes ArchitectureFree lesson

Creating Resources with kubectl create and apply

Understanding the difference between imperative create and declarative apply commands.

Creating Resources with kubectl create and apply

What You'll Learn

You'll learn the fundamental difference between the imperative kubectl create command and the declarative kubectl apply command, and when to use each.

Two Ways to Create Kubernetes Resources

Kubernetes gives you two approaches to creating resources like Pods, Deployments, and Services: imperative and declarative.

Imperative: kubectl create

The kubectl create command is imperative—you're giving Kubernetes a direct order: "Create this resource now."

kubectl create deployment nginx --image=nginx

Think of it like ordering at a restaurant by telling the waiter exactly what to do: "Bring me a burger, fries, and a drink." It's fast and simple for one-off tasks, but if you want to modify something later, you need to issue new commands (kubectl edit, kubectl delete, then recreate).

Limitation: You can't run kubectl create twice on the same resource—it will error because the resource already exists.

Declarative: kubectl apply

The kubectl apply command is declarative—you're describing the desired state in a YAML or JSON file, and Kubernetes figures out what needs to happen.

kubectl apply -f deployment.yaml

This is like giving a blueprint to a builder: "Make it look like this." If you run apply again with changes, Kubernetes intelligently updates only what's different. This approach is repeatable and version-controllable, making it ideal for production environments.

Which Should You Use?

  • create: Quick experiments, learning, one-time tasks
  • apply: Production workflows, GitOps, infrastructure as code

Key Takeaway: Use kubectl create for imperative, one-time commands, and kubectl apply with YAML files for declarative, repeatable infrastructure management that can be versioned and audited.