Understanding Kubernetes States: Declared vs Observed states Explained

|
Published:
|
|
Kubernetes States: Declared vs Observed States

In Kubernetes, effective state management is crucial for maintaining the stability and reliability of your clusters. Kubernetes relies on two key state concepts: Declared State and Observed State. These states are integral to the orchestration system’s operation, ensuring that applications run as intended. This guide will explore these concepts in depth, highlighting their key differences.

Kubernetes States: Declared vs Observed States

Declared State (Desired State)

The declared state in Kubernetes, also known as, the desired state, represents the user’s intended configuration or specification for a specific Kubernetes resources. This state is defined declaratively using YAML or JSON manifests files.It encapsulates the desired attributes and configurations required for resources to function correctly.

The desired/declared state specifies characteristics such as the number of replicas, container images, resource limits, networking configurations, and other settings necessary for the resources to operate according to the user’s specifications.

Take for example, for a Deployment, the desired state may specify that three replicas of a web application should be running, using a specific container image and exposing a certain port.

In short, the declared or desired Kubernetes cluster state is essentially your blueprint of how you want your application to run in the cluster.

Observed State (Actual State)

On the other hand, Kubernetes cluster controllers dynamically determined the current state of Kubernetes resources, including their availability, health, and configuration etc. This is what is called observed or actual Kubernetes state.

The actual state reflects the real-time status and condition of resources within the Kubernetes cluster.

The Kubernetes control plane constantly monitors the cluster to ensure the observed state aligns with the desired state. This involves a continuous loop. For example:

  1. The control plane checks the desired state: It reads the deployment configurations, including the number of replicas and resource requests.
  2. The control plane observes the actual state: It checks how many pods are currently running for the deployment and their resource utilization.
  3. Discrepancy detected? Take action!: If the observed state deviates from the desired state, the control plane takes corrective measures. It might scale the deployment up or down, reschedule pods on healthy nodes, or initiate container restarts.

Importance of Resource States in Kubernetes

  • Declarative Management: You define what you want, and Kubernetes takes care of the how. This simplifies application deployment and reduces configuration complexity.
  • Self-Healing: Kubernetes automatically reconciles discrepancies in resource states, ensuring your applications remain available and resilient to failures.
  • Predictability: By managing the desired state, you can predict the behavior of your applications and the overall cluster health.
  • Consistency: Maintains a consistent environment even when changes or failures occur.
  • Scalability: Facilitates the scaling of applications by managing the desired and actual number of instances.
  • Reliability: Ensures that applications are running as expected.
  • Recovery: Helps in the automatic recovery of applications from failures.

Conclusion

In summary, in Kubernetes, the declared state is the desired configuration of your cluster, while the observed state is the actual current condition. Managing these states effectively ensures that your applications run as intended.

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
Kifarunix
Linux Certified Engineer, with a passion for open-source technology and a strong understanding of Linux systems. With experience in system administration, troubleshooting, and automation, I am skilled in maintaining and optimizing Linux infrastructure.

Leave a Comment