What Is kubectl apply in Kubernetes? Telling the Cluster What You Want

What Is kubectl apply in Kubernetes? Telling the Cluster What You Want

A beginner-friendly guide to the most-used command in Kubernetes: how it turns a description in a file into a living, running system, how it decides what to change, and how to use it safely.

Imagine you are decorating a room with the help of an interior designer. You could give step-by-step orders all day: “Move the sofa left, now lift the lamp, now hang that picture.” Or you could hand over a photograph of exactly how you want the finished room to look, and say, “Make the room look like this.” The designer looks at the room as it is today, compares it with the photograph, and does only the work needed to close the gap. If the room already matches, the designer does nothing. That second way of working is exactly what the command kubectl apply does for a Kubernetes cluster.

1Two Ways to Give Orders: Imperative and Declarative

To understand kubectl apply, we first need to understand a choice every Kubernetes user makes.

The Imperative Way: Do This, Then Do That

In the imperative style, you give the system a direct command for each action. Create this Pod. Scale that Deployment to five copies. Delete that Service. Each command does one thing, right now. This is quick for experiments and one-off tasks, but it leaves no record of what you did, and repeating the same steps later on another cluster means remembering every command.

The Declarative Way: Here Is the Goal

In the declarative style, you write down the end result you want in a file and hand the file to the system. You do not say how to get there. The system works out the steps by comparing what exists with what you described. The file becomes a permanent, shareable, reviewable record of your intent.

Simple Analogy

Imperative is giving a taxi driver turn-by-turn directions: “Left here, right there.” Declarative is telling the driver the destination and letting a navigation system find the route. If a road is closed, the navigation system adjusts by itself. You only care about where you end up.

i
Key Idea

The command kubectl apply is the standard tool for the declarative style. It says: “Make the cluster match what is written in these files.”

2Why kubectl apply Exists

Real systems change constantly, and typing commands by hand does not survive contact with reality.

Repeatability

An application in Kubernetes is described by many small objects: Deployments, Services, configuration objects, and more. Rebuilding them by hand on a second cluster, or after a disaster, would be slow and error-prone. If all of them are described in files, one command recreates everything, identically, every time.

History and Teamwork

Files can be stored in a version-control system such as Git. Every change gets a name, a date, and a reviewer. If a change breaks something, you can see exactly what changed and go back to the previous version. That is impossible when changes were made by typing commands into a terminal and forgetting them.

Safe Repetition

Running the same apply command twice should not cause trouble. If nothing has changed, nothing happens. If one small thing changed, only that small thing is updated. This property, where repeating an action gives the same result as doing it once, is called idempotence, and it makes the command safe to run again and again from scripts and automated pipelines.

Simple Analogy

Pressing the “set temperature to 24 degrees” button on an air conditioner a second time does not make the room colder. It stays at 24. The button expresses a goal, not a repeated action. Applying the same file twice works the same way.

1
File describes the goal
Safe
To repeat as many times as needed
Tracked
In version control with full history

3Core Building Blocks You Must Know

Eight small terms carry almost the entire story of kubectl apply.

Term 1

Manifest

A file, usually written in a simple text format, that describes one or more Kubernetes objects you want to exist.

Term 2

Resource or Object

One thing in the cluster, such as a Pod, a Deployment, a Service, or a ConfigMap.

Term 3

Desired State

How you want things to be, as written in your manifest. It is your goal.

Term 4

Live State

How things really are right now inside the cluster. It may differ from your goal.

Term 5

API Server

The front door of the cluster. Every command, including apply, is delivered to it and stored by it.

Term 6

Controller

A background worker that keeps pushing live state toward desired state, for example by creating missing Pods.

Term 7

Namespace

A named room inside the cluster that separates teams or environments. Apply acts inside one at a time.

Term 8

Field Manager

A label recording who last set a particular field, used by the newer server-side way of applying.

Simple Analogy

The manifest is the architect’s drawing. The live state is the building as it stands today. The API server is the city office where drawings are submitted, and the controllers are the construction crews who slowly make the building match the drawing.

4What Happens When You Run kubectl apply

Behind one short command lies a tidy chain of small steps.

The Journey in Plain Words

First, kubectl reads your file and checks that it is properly formed. Next, it works out which object each part describes and where it belongs. Then it sends the description to the API server. The API server compares your description with what is already stored. If the object does not exist, it creates it. If it exists but differs, it updates only what needs changing. If it exists and already matches, it does nothing. Finally, the controllers notice the new or changed description and start working to make reality match it.

flowchart TD
    A["You write a manifest file"] --> B["kubectl apply reads and checks the file"]
    B --> C["Sends the description to the API server"]
    C --> D{"Does the object already exist?"}
    D -->|"No"| E["Create it"]
    D -->|"Yes"| F{"Does it differ?"}
    F -->|"Yes"| G["Update only what changed"]
    F -->|"No"| H["Report unchanged"]
    E --> I["Controllers make reality match"]
    G --> I
        
FIG 1 — The decision path of a single apply
i
Good to Know

Apply itself finishes quickly. It only records your intent. The real work of starting Pods and moving traffic continues afterwards in the background, so a successful apply does not mean everything is already running.

5The Three Possible Outcomes

Every object in your files ends up in exactly one of three states after an apply.

Created

The object did not exist before, so Kubernetes made a brand-new one. You see a short message saying so, naming the object.

Configured

The object existed but differed from your description, so Kubernetes updated it. This is the message you will see whenever you change a file and apply it again.

Unchanged

The object already matched your description exactly, so nothing was touched. This is the sign of a healthy, stable system and of idempotence at work.

Simple Analogy

A gardener given a plan for a flower bed either plants what is missing, adjusts what has grown the wrong way, or simply walks away when the bed already looks right. The three messages are the gardener’s report.

!
Common Mistake

Reading “configured” as a sign of trouble. It just means a change was applied. Trouble shows up as error messages or as Pods that fail to become ready afterwards.

6Apply Compared with Its Neighbours

Kubernetes offers several ways to change objects. Knowing the differences prevents confusion.

Command StyleApproachIf Object ExistsIf Object Is MissingBest For
applyDeclarativeUpdates only what differsCreates itEveryday management from files
createImperativeFails with an errorCreates itQuick one-time creation
replaceImperativeOverwrites the whole objectFails with an errorDeliberate full replacement
patchImperativeChanges only the fields you nameFails with an errorSmall targeted edits
editInteractiveOpens the live object for hand editingFails with an errorQuick manual fixes, not for records
Simple Analogy

Create is like opening a brand-new notebook and refusing to write if the notebook already exists. Replace is like tearing out a page and writing a fresh one. Patch is like correcting one word with a pen. Apply is like handing over the finished page and letting a helper work out which words to fix.

!
Common Mistake

Mixing styles carelessly on the same objects. Creating something by hand and later applying files over it, or editing live objects while also applying files, leads to surprises because the tracking information that apply relies on may be missing or out of date.

7Client-Side Apply: The Three-Way Merge

The classic way apply works involves a clever comparison of three pictures.

Three Pictures

To decide what to change, the classic method compares three things: what you applied last time, what is live in the cluster right now, and what your file says today. It uses these three to work out what you added, what you removed, and what someone else changed on purpose.

1

Last Applied

Every time you apply, a copy of your file is stored on the object in a special note called an annotation. This is the memory of what you previously asked for.

2

Live State

The object as it currently exists, including fields filled in by the cluster itself or by other tools.

3

New File

The manifest you are applying right now, representing your current goal.

4

The Merge

Fields present in the last applied copy but missing from the new file are removed. Fields in the new file are added or updated. Fields set only by others, and never mentioned by you, are left alone.

flowchart LR
    A["Last applied copy"] --> D["Three-way comparison"]
    B["Live object in cluster"] --> D
    C["New manifest file"] --> D
    D --> E["Remove what you dropped"]
    D --> F["Add or update what you changed"]
    D --> G["Leave alone what others set"]
        
FIG 2 — Three pictures combine to decide the exact change
Simple Analogy

Think of a shared shopping list on a fridge. You remember what you wrote last week, you see what is on the list now, and you know what you want today. If you crossed out milk from your plan, you remove milk. If your flatmate added biscuits, you leave biscuits alone because you never wrote them.

i
Practical Tip

This is why deleting a line from your file and applying again really does remove that setting from the live object, but only if you had previously applied it. The memory of your last apply is what makes the removal possible.

8Server-Side Apply: Who Owns Which Field?

A newer method moves the comparison work into the cluster and tracks ownership of each field.

The Idea of Ownership

In server-side apply, the API server itself keeps track of who set each individual field of an object. Each tool or person that applies changes is called a field manager. When you apply a file, you become the owner of the fields you specified. Another tool, such as an automated controller, may own other fields on the same object.

Conflicts Are Made Visible

If you try to change a field that another manager owns and the value differs, the server reports a conflict instead of silently overwriting. You then decide: adjust your file so you no longer claim that field, or deliberately force your value and take ownership. This prevents two tools from fighting invisibly over the same setting.

Simple Analogy

Imagine a shared document where every paragraph has the name of its author beside it. If two people try to rewrite the same paragraph, the system stops and asks them to sort it out, instead of letting the last person quietly erase the other one’s work.

Advantages of Server-Side Apply

  • Clear ownership of every field
  • Conflicts are reported instead of hidden
  • Works well when several tools manage one object
  • Handles very large objects that would not fit in the last-applied note
  • Comparison logic lives in one consistent place, the server

Disadvantages / Trade-offs

  • Ownership rules take time to learn
  • Conflicts can interrupt automated pipelines until resolved
  • Forcing a value can take fields away from other tools
  • Switching an existing object from the classic method needs care
i
Good to Know

Large custom objects can exceed the size limit of the last-applied note used by the classic method. Server-side apply avoids that problem, which is one reason many automated delivery tools now prefer it.

9What Can You Apply? Files, Folders, and More

Apply is flexible about where your descriptions come from.

Source 1

A Single File

The simplest case. One file can describe one object, or several objects separated by a divider line.

Source 2

A Whole Folder

Pointing at a folder applies every manifest inside it. Adding a recursive option also includes subfolders.

Source 3

A Web Address

A manifest hosted online can be applied directly. Convenient, but it needs careful trust, as Chapter 17 explains.

Source 4

Standard Input

Descriptions can be piped in from another program, which is how many scripts and templating tools work.

Source 5

A Kustomization

A folder with a kustomization file that layers small, environment-specific changes on top of a common base.

Templating Tools Feed Into Apply

Many teams use tools that generate manifests from templates and settings, such as package managers for Kubernetes. At the end of the pipeline, these tools still hand plain manifests to the cluster in the same declarative way. Understanding apply therefore helps you understand almost every deployment tool built on Kubernetes.

Simple Analogy

You can hand a builder one drawing, a whole binder of drawings, or a set sent by courier. However the drawings arrive, the builder’s job is the same: compare with what exists and build the difference.

10Look Before You Leap: Dry Runs and Diffs

The safest apply is the one you previewed first.

Two Kinds of Preview

Client Dry Run

kubectl checks your files locally and shows what it would send, without contacting the cluster’s decision logic. It catches spelling errors and basic mistakes quickly.

Server Dry Run

The request goes all the way to the API server, which runs every check, including rules set by administrators, and then stops before saving anything. It is far more realistic, because it tells you whether the cluster would truly accept your change.

The Diff Command

A separate command shows a line-by-line comparison between the live state and what would result if you applied your files. It is like a proofreader’s marked-up page, showing exactly what would be added, removed, or changed.

Simple Analogy

Before sending an important email, you read it once more. A dry run is proofreading for grammar. A server dry run is asking a colleague whether the recipient’s system would accept it. A diff is comparing today’s draft with yesterday’s, highlighting every difference.

i
Habit to Build

In shared or production clusters, always look at a diff before applying. Make it a required step in your automated pipeline so nobody applies a change they have not seen.

11Deleting Things: The Surprise About Removed Files

Apply is very good at creating and updating, but it does not delete just because a file vanished.

An Absent File Says Nothing

If you remove a manifest from your folder and run apply on the folder again, the object it described stays alive in the cluster. Apply only looks at the descriptions you give it. It has no way of knowing that something missing from your folder was meant to be removed, rather than simply not mentioned this time.

How to Remove Things Properly

1

Delete by File

Use the delete command with the same file, and Kubernetes removes every object that file describes.

2

Use Pruning with Care

Apply can be told to delete previously applied objects that are no longer in the set you provide, usually guided by a label. It is powerful and should be used with a very precise selection.

3

Use Automated Delivery Tools

Continuous delivery tools can track everything they created and remove what disappears from the source, offering a safer form of pruning.

Simple Analogy

If you stop mentioning a guest on the invitation list, that guest does not vanish from the party. Someone still needs to escort them out. Removing something from the plan and removing it from reality are two separate acts.

!
Common Mistake

Believing that deleting a file from Git removes the object from the cluster. Without a pruning mechanism, it silently stays running and can cost money or cause confusion for months.

12Order and Dependencies

Some objects need others to exist first, and apply is not a mind reader.

What Depends on What

A namespace must exist before objects can be placed inside it. A custom resource definition, which teaches the cluster about a new kind of object, must be accepted before objects of that new kind can be created. A ConfigMap or Secret should exist before a Pod that uses it can start successfully.

How Apply Handles Order

When applying a folder, files are processed in name order, and within a single file, objects are processed from top to bottom. Kubernetes cannot always guess the right order across unrelated files. Teams often number their files or separate them into stages so that foundations go first and the rest follow.

Simple Analogy

You cannot hang curtains before the wall exists. The instructions for building the house must be in an order that makes sense, even if the builder can carry out each individual instruction cleverly.

i
Practical Tip

Kubernetes objects that depend on others usually recover on their own once the missing piece appears, because controllers keep retrying. Even so, giving foundations first is cleaner and produces fewer confusing temporary errors.

13Fields That Refuse to Change

Some settings are locked once an object is born, and apply cannot unlock them.

Immutable Fields

Certain fields cannot be edited after an object is created. Examples include the label selector of a Deployment, and the internal address given to a Service. If your manifest changes such a field, the API server rejects the apply with an error message that names the field and says it cannot be changed.

What to Do

The usual solution is to delete the object and apply the corrected description again, planning for a short interruption. For workloads, a safer route is often to create a new object side by side, move traffic to it, and only then remove the old one.

Simple Analogy

You can repaint a house, but you cannot move its foundation. If the foundation must move, you rebuild. Immutable fields are the foundation of an object.

!
Common Mistake

Deleting and recreating a production object in a hurry without planning. During the gap, users may see errors. Prepare a plan for traffic before touching anything that cannot be updated in place.

14Apply and Other Controllers: Who Owns the Replica Count?

Other parts of the cluster change objects too, and apply must share the stage politely.

The Classic Trap

Suppose your Deployment file says three copies, but an autoscaler has raised the live number to twelve because traffic is heavy. If your file keeps saying three and you apply it again, you will push the count back to three at the worst possible moment. The file and the autoscaler are both trying to own the same field.

The Fix

Leave the replica count out of the file when another tool manages it. Because you never mention the field, apply never claims it, and the autoscaler is free to control it. The same principle applies to any field that other controllers or tools set on your behalf.

Simple Analogy

If the air-conditioner’s thermostat manages the temperature, you should not also write “24 degrees” on a sticky note and keep resetting it by hand. Choose one owner for each setting.

Good Habits

  • One clear owner for every field
  • Omit fields that automation manages
  • Use server-side ownership tracking when several tools share an object
  • Document which tool owns which setting

Bad Habits

  • Letting files and controllers both set the same field
  • Editing live objects by hand outside the files
  • Forgetting that a second apply may undo automatic changes
  • Ignoring conflict warnings

15Life of One Apply: From File to Running Pods

Let us follow a change to a Deployment from your keyboard to the running application.

sequenceDiagram
    participant Y as You
    participant K as kubectl
    participant A as API Server
    participant D as Deployment Controller
    participant N as Nodes
    Y->>K: Apply the edited manifest
    K->>A: Send the description
    A->>A: Validate and compare with stored object
    A-->>K: Report configured
    K-->>Y: Show the result message
    A->>D: Notify of the changed Deployment
    D->>N: Start new Pods with the new version
    N-->>D: New Pods become ready
    D->>N: Stop old Pods gradually
    Note over D,N: Rolling update keeps the application available
        
FIG 3 — A change travels from your file to the running application
1

You Edit and Apply

You change the image version in your file and apply it. The command returns quickly with a result message.

2

The Server Validates and Stores

The API server checks the change against its rules and saves the new desired state.

3

The Controller Reacts

The Deployment controller notices that the description changed and begins a rolling update.

4

New Pods Replace Old Ones

New Pods start, pass their readiness checks, and take traffic while old Pods are removed step by step.

5

You Watch the Rollout

A separate status command lets you wait and see when the update finishes or when it gets stuck.

“Apply records your intention. The cluster does the rest, patiently and in the background.”

16When Things Go Wrong: Failure Modes and Fixes

Most apply problems fall into a few familiar shapes.

The File Is Malformed

A spacing error, a missing colon, or a misspelled field name produces a validation message pointing at the problem. Fix the file and apply again.

Wrong Cluster or Namespace

The command worked, but on the wrong target. Always confirm the current cluster and namespace before applying. This is one of the most common and most costly mistakes.

Permission Denied

Your account is not allowed to create or update that kind of object in that namespace. Ask an administrator to adjust your permissions rather than working around them.

Immutable Field Error

Your change touches a locked field. Plan a deletion and recreation, or create a new object next to the old one.

Field Conflict

With server-side apply, another manager owns a field you are trying to set. Decide who should own it, and either remove it from your file or deliberately take it over.

Applied but Not Working

The apply succeeded, but Pods are stuck or crashing. Look at the workload’s status, events, and logs. A successful apply only means your description was accepted.

A Calm Debugging Path

1

Read the Error Message Slowly

Apply errors are usually specific. They often name the exact field and the reason it was refused.

2

Confirm Your Target

Check which cluster and namespace your command is pointing at before doing anything else.

3

Run a Server Dry Run and a Diff

These show what the cluster thinks of your change without saving anything.

4

Inspect the Object and Its Events

Describing the object often reveals scheduling problems, missing references, or image download failures.

5

Fix the File, Not the Live Object

Correct the manifest in version control and apply again, so your record and the cluster stay in agreement.

17Security Considerations

Apply can change almost anything in a cluster, so it must be used with respect.

Risk 1

Applying Untrusted Manifests

A manifest from an unknown source can create powerful, dangerous objects. Applying it blindly is like running an unknown program with full permissions.

Risk 2

Secrets in Files

Writing passwords into manifests that are stored in shared repositories exposes them to everyone with access.

Risk 3

Overly Broad Permissions

An account allowed to apply anything anywhere can cause enormous damage through a slip or a stolen credential.

Risk 4

Risky Settings Sneaking In

Files may request privileged containers or unsafe access to machines, weakening the security of the whole cluster.

Risk 5

Wrong Target

Applying a test change to a production cluster by mistake can cause real outages.

Simple Analogy

Handing over a set of building plans to a construction crew is powerful. If the plans came from a stranger, they might include a secret door or a weakened wall. You would read them carefully before letting the crew start.

Practical Protections

Read manifests from outside sources before applying them, and prefer sources you trust. Keep secrets out of plain files, using encrypted storage or dedicated secret management instead. Give people and automation only the permissions they truly need, limited to particular namespaces. Use admission rules that block unsafe settings, so risky objects are refused even if someone tries to apply them. Prefer automated delivery from version control with reviews, rather than everyone applying from their own laptops. Clearly label your terminal or tooling with the current cluster name so a wrong target is obvious before you press enter.

!
Common Mistake

Applying a manifest straight from a web address you found online because it saves a minute. The few seconds saved are not worth the risk of installing something you never read.

18Monitoring, Logging, and Auditing Changes

If apply can change everything, you should be able to see everything it changed.

What to Watch

Cluster audit logs record who applied what, and when. Events on each object describe what the controllers did in response. Rollout status shows whether an update finished or stalled. Combined, these tell the full story of every change.

Who
Recorded in audit logs for every change
What
Visible through diffs and version history
Result
Shown by events and rollout status
What to WatchWhy It MattersWarning Sign
Audit log of changesAnswers who changed whatUnexpected changes from unknown accounts
Rollout statusShows if an update completedRollouts stuck for a long time
Object eventsExplain scheduling and startup problemsRepeated warnings after an apply
Drift between files and clusterShows manual changes outside version controlDiffs that are not empty after a clean apply
Pipeline resultsShow failures in automated deliveryFrequent failed or skipped applies

Catching Drift

Drift means the live cluster no longer matches your files, usually because someone made a manual change. Running a diff on a schedule, or using tools that continuously compare and correct, keeps the cluster honest and your files trustworthy.

Simple Analogy

A hotel keeps a register of who entered which room and when. If a room’s lock is changed without a record, the register no longer matches reality. Audit logs and diffs are that register for your cluster.

19Design Patterns and Anti-Patterns

Good habits make apply boring, and boring is exactly what you want.

Pattern: Files as the Single Source of Truth

Every object in the cluster is described in version control. If it is not in the files, it does not exist, or it is a mistake to be corrected.

Pattern: Base Plus Environment Layers

A common base describes the application, while small overlays supply the differences between test, staging, and production.

Pattern: Review, Diff, Apply

Changes are proposed, reviewed by a teammate, previewed with a diff, and only then applied, ideally by automation.

Pattern: Continuous Delivery from Git

A tool inside or beside the cluster watches a repository and applies changes automatically, also correcting any manual drift.

Pattern: Small, Frequent Changes

Applying small changes often is safer than large ones rarely, because each change is easier to understand and easier to reverse.

ANTI-PATTERN-01 Avoid
Problem

Editing live objects by hand in the cluster, without changing the files.

Why It’s Harmful

The files no longer describe reality. The next apply may silently undo the manual fix, or the manual fix may be lost when the cluster is rebuilt.

Correct Approach

Make every change in the files, review it, and apply it. Treat manual edits as emergencies to be copied back into files immediately.

ANTI-PATTERN-02 Avoid
Problem

Applying to production directly from personal laptops with no review or record.

Why It’s Harmful

Changes are unreviewed, uneven, and hard to trace. A tired person applying the wrong file to the wrong cluster can cause an outage.

Correct Approach

Use an automated pipeline with reviews and restricted permissions, so production changes are consistent and traceable.

ANTI-PATTERN-03 Avoid
Problem

Mixing create, replace, edit, and apply on the same objects with no rule.

Why It’s Harmful

The tracking information used by apply becomes stale or missing, producing confusing merges and surprising deletions of settings.

Correct Approach

Pick one management style per object, and stay with it. For declarative work, use apply consistently.

20Best Practices and Common Mistakes

A short checklist that prevents most apply trouble before it starts.

Best Practices

  • Store all manifests in version control and review changes
  • Preview with a server dry run and a diff before applying
  • Confirm the target cluster and namespace every time
  • Keep one clear owner for each field and omit fields managed by automation
  • Use a consistent management style for each object
  • Keep secrets out of plain manifests
  • Watch the rollout after every change to a workload

Common Mistakes

  • Applying without checking the current cluster
  • Expecting deleted files to delete objects
  • Leaving a fixed replica number when an autoscaler manages it
  • Ignoring conflict warnings and forcing changes casually
  • Applying manifests from untrusted addresses
  • Assuming a successful apply means everything is healthy
i
Habit to Build

Before pressing enter on any apply, ask three questions. Where am I applying this? What exactly will change? Who else might own these settings? Those three questions prevent most of the painful mistakes.

21Real-World Examples

Here is how apply quietly powers everyday cluster work.

Releasing a New Version of a Shopping Site

A developer changes the image version in a file, opens a review, and once approved, the pipeline applies it. Kubernetes rolls the new version out gradually, and the change history in Git records who released what and when.

Rebuilding After a Disaster

A cluster is lost. Because every object is described in files, the team creates a fresh cluster and applies the same folders. Within an hour, the same application is running again, identically.

Three Environments, One Base

A company keeps one base description of its application, with small overlays for test, staging, and production. Applying the matching overlay gives each environment the right size and settings, while sharing the same core.

Continuous Delivery Tool Watching a Repository

A delivery tool inside the cluster continuously compares the repository with the cluster. When someone manually changes a Deployment, the tool notices the drift and reapplies the file, undoing the unreviewed change.

Sharing Objects Between Two Tools

A platform team defines a Deployment while an autoscaler manages its replica count. Using field ownership, both coexist peacefully: each tool changes only the fields it owns.

22Frequently Asked Questions

Q1What does kubectl apply actually do?

It reads descriptions of objects from files or other sources and makes the cluster match them, creating missing objects and updating changed ones while leaving matching ones alone.

Q2What is the difference between apply and create?

Create is a one-time instruction that fails if the object already exists. Apply is declarative and safe to repeat, creating the object if missing and updating it if present.

Q3Is it safe to run apply twice?

Yes. If nothing changed, the second run reports the objects as unchanged. This repeat-safety is one of the main reasons to use it.

Q4Does apply delete objects when I remove their files?

No, not by itself. Removing a file only stops you from mentioning the object. To remove it, delete it explicitly, use careful pruning, or rely on a delivery tool that tracks what it created.

Q5What is server-side apply?

A newer method where the cluster tracks which manager owns each field. It reports conflicts instead of silently overwriting, and copes better with very large objects and shared control.

Q6Why did my apply fail on an immutable field?

Some fields cannot change once an object exists. You must delete and recreate the object, or create a replacement alongside it and move traffic over.

Q7How can I preview what apply would do?

Use a server dry run to see whether the cluster would accept the change, and the diff feature to see a line-by-line comparison between the live state and your files.

Q8Why did apply reset my replica count?

Your file still contained a fixed number, and apply enforced it over the value set by an autoscaler. Remove the field from the file when another tool owns it.

Q9Does a successful apply mean my application is running?

No. It only means your description was accepted. The controllers then need time to start Pods and move traffic, so always check rollout status afterwards.

Q10Should everyone apply changes from their own laptop?

For learning and test clusters, that is fine. For shared and production clusters, an automated, reviewed pipeline is safer, more consistent, and leaves a clear record of every change.

23Summary and Key Takeaways

The command kubectl apply is how most people tell a Kubernetes cluster what they want. Instead of issuing a string of orders, you write the goal in a file and let the cluster compare it with reality and close the gap. It creates what is missing, updates what differs, and leaves alone what already matches, so it is safe to repeat. Behind the scenes it uses either a classic three-way comparison or the newer field-ownership method. With previews, careful targeting, clear ownership of each setting, and a review-and-automate habit, apply becomes a calm, reliable way to run everything from a single test service to a large production platform.

Key Takeaways

  • Declarative, not step-by-step — you describe the goal in a file, and apply works out how to reach it from the current state.
  • Safe to repeat — running it again on an unchanged file reports everything as unchanged, which suits scripts and pipelines.
  • Two ways to compare — the classic method uses a three-way merge with a saved last-applied copy, while server-side apply tracks who owns each field.
  • Preview first — use a server dry run and a diff to see exactly what would change before it does.
  • Missing files do not delete — removing a manifest does not remove the object, so use explicit deletion or carefully controlled pruning.
  • Share fields deliberately — leave out settings that other tools, like autoscalers, manage, and pay attention to conflict warnings.
  • Accepted is not healthy — a successful apply means the description was stored, so always watch the rollout and confirm you targeted the right cluster.