DevOpsLesson
DevOpsLesson

Free, comprehensive DevOps tutorials and learning roadmaps. Master Docker, Kubernetes, CI/CD, and more.

Stay Updated

Get notified about new tutorials and features.

Tutorials

  • What is DevOps?
  • Docker Tutorial
  • Terraform Tutorial
  • CI/CD Pipeline
  • All Tutorials

Roadmaps

  • DevOps Engineer
  • Cloud Engineer
  • SRE Path
  • All Roadmaps

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 DevOpsLesson. All rights reserved.

DOCKERKUBERNETESTERRAFORMAWSCI/CDLINUXGITDEVOPS ROADMAPCLOUD ROADMAPSRE ROADMAPGIT CHEATSHEETDOCKER CHEATSHEETK8S CHEATSHEETTF CHEATSHEETLINUX CHEATSHEETDOCKERFILE LINTERYAML VALIDATORCRON PARSERREGEX TESTER

Kubernetes Tutorial

Introduction to Kubernetes
Kubernetes Architecture
Installing Kubernetes
kubectl Basics
Kubernetes Pods
Kubernetes Deployments
Kubernetes Services
ConfigMaps and Secrets
Kubernetes Storage
Kubernetes Namespaces
Kubernetes Resource Management
Helm for Kubernetes
Kubernetes Monitoring

kubectl apply and delete

PreviousPrev
Next

Create, update, compare, and remove Kubernetes resources using both declarative manifests and imperative helper commands.

Declarative Resource Management

The most common Kubernetes workflow is to store manifests in files and use kubectl apply to create or update resources.

Apply a Manifest

kubectl apply -f deployment.yaml
kubectl apply -f k8s/

apply is powerful because it works for both creation and updates.

Delete a Manifest

kubectl delete -f deployment.yaml
kubectl delete -f k8s/

Deleting by file is useful when you want to remove the exact resources defined in a manifest set.

Delete by Resource Type and Name

kubectl delete pod my-pod
kubectl delete deployment web

This is handy for quick cleanup, but for team workflows, deleting from files is often clearer and safer.

Imperative Create Commands

kubectl create deployment web --image=nginx
kubectl expose deployment web --port=80 --target-port=80 --type=ClusterIP

These are great for fast demos or generating starting YAML.

Generate YAML Without Creating Anything

One of the most useful tricks is --dry-run=client -o yaml.

kubectl create deployment web --image=nginx --dry-run=client -o yaml
kubectl create namespace demo --dry-run=client -o yaml

This lets you quickly scaffold a manifest, then save and edit it.

Compare Changes Before Applying

kubectl diff -f deployment.yaml

kubectl diff shows the difference between your file and the live resource. That helps you catch accidental changes before they hit the cluster.

Recommended Workflow

kubectl create deployment web --image=nginx --dry-run=client -o yaml
kubectl diff -f deployment.yaml
kubectl apply -f deployment.yaml
kubectl delete -f deployment.yaml

Why apply Is Preferred

apply supports the declarative model: you describe where you want the system to end up.

Think of apply like updating a blueprint rather than manually moving bricks one by one.

That mindset scales better in teams and production systems.

Exercise

Dry Run Trick

Why is `--dry-run=client -o yaml` so useful?

Exercise

Diff Benefit

What is the main value of `kubectl diff -f deployment.yaml`?

PreviousPrev
Next

Continue Learning

Installing kubectl

Install kubectl on macOS, Linux, or Windows, verify it works, and understand how kubeconfig connects the CLI to a cluster.

18 min·Easy

kubectl Basics

Learn how kubectl fits into Kubernetes workflows and when to use imperative commands versus declarative manifests.

15 min·Easy

kubectl get and describe

Inspect pods, nodes, deployments, and services with kubectl get and use describe output to understand object behavior and events.

18 min·Easy

Explore Related Topics

Do

Docker Tutorials

Build the containers Kubernetes orchestrates

Te

Terraform Tutorials

Provision Kubernetes clusters as code

Try the Tool

YAML Validator

Validate Kubernetes manifests and any YAML files instantly.

On This Page

Declarative Resource ManagementApply a ManifestDelete a ManifestDelete by Resource Type and NameImperative Create CommandsGenerate YAML Without Creating AnythingCompare Changes Before ApplyingRecommended WorkflowWhy `apply` Is Preferred