Kubernetes
medium

Questão de Kubernetes #019e3a4f

Enunciado da Questão
Kubernetes
#kubernetes
#statefulset
#split-brain
#distributed-systems
#consensus
Médio

Which Kubernetes feature would you use to guard against split brain scenarios with your distributed application?

A

Replication controllers

B

Consensus protocols

C

Rolling updates

D

StatefulSet

Correta

Explicação Oficial / Explicações da Comunidade

Summary

To guard against split brain scenarios in a distributed application, you should use a StatefulSet. StatefulSets provide stable, unique network identifiers and persistent storage for each pod, which is essential for applications that require ordered deployment and scaling, such as databases and distributed systems. Split brain occurs when a cluster splits into multiple partitions that cannot communicate, leading to conflicting state. StatefulSets help prevent this by ensuring that each pod has a unique identity and that storage is tied to that identity, allowing the application to use consensus protocols (like Raft or Paxos) to maintain consistency.

How It Works

StatefulSets assign each pod a stable hostname (e.g., pod-0, pod-1) and a persistent volume claim that persists across rescheduling. This allows distributed applications to use leader election and consensus algorithms to coordinate state. For example, a database cluster using a StatefulSet can have each pod know its role (leader/follower) based on its ordinal index, and if a network partition occurs, the pods in the majority partition can continue operating while the minority partition waits, preventing split brain.

Why the Correct Answer is Right

  • StatefulSet is designed for stateful applications that require stable identities and persistent storage. It provides the foundation for implementing consensus-based coordination, which is the standard defense against split brain.

Why the Incorrect Answers are Wrong

  • Replication controllers are a legacy resource that ensures a specified number of pod replicas are running, but they do not provide stable identities or persistent storage. Pods created by a replication controller are interchangeable and can be rescheduled with new names, making them unsuitable for applications that need to maintain state across restarts.
  • Consensus protocols (like Raft or Paxos) are algorithms used to achieve agreement among distributed nodes, but they are not a Kubernetes feature. Kubernetes does not implement consensus protocols directly; instead, it provides resources like StatefulSets that enable applications to use such protocols.
  • Rolling updates are a deployment strategy to update pods gradually with zero downtime. They do not address split brain scenarios, as they focus on updating application versions rather than maintaining consistency during network partitions.

Key Takeaway

Use StatefulSets for distributed applications that require stable identities and persistent storage to implement consensus-based coordination and avoid split brain.