Overview: From Imperative to Declarative

To deeply understand Kubernetes, we must understand the radical shift it brought to application management. This is the transition from an Imperative approach to a Declarative one.

1. The Imperative Approach: You are the Micromanager

In the past, with tools like Docker Compose or manual scripts, you acted as a manager giving step-by-step commands.

  • You would tell the system: "Run a container from this image," "Expose this port," "Connect this network."
  • This approach is simple and direct, but problems arise when something goes wrong.
  • If a container stops working, the system won't do anything on its own.
  • You are responsible for detecting the problem and issuing a new command to restart it.

In short, you monitor the state yourself and issue commands step-by-step.

2. The Declarative Approach: You Set the Vision

With Kubernetes, your role changes completely. You no longer give commands; instead, you describe the "Desired State" of your application in YAML files.

  • You tell Kubernetes: "I want 3 replicas of my application to be running continuously."
  • "I want these replicas to be accessible via an internal DNS name."
  • "I want to update the application smoothly with zero downtime."

After that, Kubernetes takes over. It acts as a "mastermind" or an intelligent control system. Its job is to monitor the "Current State" and constantly compare it with the "Desired State" you described.

If it finds any difference—like one of the replicas crashing—it automatically takes the necessary action (such as creating a new one) to return to the desired state. This is the essence of Kubernetes: Control Loops that work tirelessly to match reality with your vision.

Conclusion: "What" You Want, Not "How"

You describe "what" you want, and Kubernetes figures out "how" to achieve and maintain it.

Overview: From Imperative to Declarative