More about Kubernetes Storage
- Kubernetes StorageClass: Concepts and Common Operations
- Kubernetes Data Mobility with Cloud Volumes ONTAP
- Scaling Kubernetes Persistent Volumes with Cloud Volumes ONTAP
- What's New in K8S 1.23?
- Kubernetes Topology-Aware Volumes and How to Set Them Up
- How to Use NetApp Cloud Manager for Provisioning Persistent Volumes in Kubernetes
- Kubernetes vs. Nomad: Understanding the Tradeoffs
- How to Set Up MySQL Kubernetes Deployments with Cloud Volumes ONTAP
- Kubernetes Volume Cloning with Cloud Volumes ONTAP
- Container Storage Interface: The Foundation of K8s Storage
- Kubernetes Deployment vs StatefulSet: Which is Right for You?
- Kubernetes for Developers: Overview, Insights, and Tips
- Kubernetes StatefulSet: A Practical Guide
- Kubernetes CSI: Basics of CSI Volumes and How to Build a CSI Driver
- Kubernetes Management and Orchestration Services: An Interview with Michael Shaul
- Kubernetes Database: How to Deploy and Manage Databases on Kubernetes
- Kubernetes and Persistent Apps: An Interview with Michael Shaul
- Kubernetes: Dynamic Provisioning with Cloud Volumes ONTAP and Astra Trident
- Kubernetes Cloud Storage Efficiency with Cloud Volumes ONTAP
- Data Protection for Persistent Data Storage in Kubernetes Workloads
- Managing Stateful Applications in Kubernetes
- Kubernetes: Provisioning Persistent Volumes
- An Introduction to Kubernetes
- Google Kubernetes Engine: Ultimate Quick Start Guide
- Azure Kubernetes Service Tutorial: How to Integrate AKS with Azure Container Instances
- Kubernetes Workloads with Cloud Volumes ONTAP: Success Stories
- Container Management in the Cloud Age: New Insights from 451 Research
- Kubernetes Storage: An In-Depth Look
- Monolith vs. Microservices: How Are You Running Your Applications?
- Kubernetes Shared Storage: The Basics and a Quick Tutorial
- Kubernetes NFS Provisioning with Cloud Volumes ONTAP and Trident
- Azure Kubernetes Service How-To: Configure Persistent Volumes for Containers in AKS
- Kubernetes NFS: Quick Tutorials
- NetApp Trident and Docker Volume Tutorial
What Is Kubernetes Deployment?
A Deployment is a Kubernetes resource object used for declarative application updates. Deployments allow you to define the lifecycle of applications, including the container images they use, the number of pods and the manner of updating them.
Deployments are fully managed by the backend in Kubernetes, with the entire update process being server side, with no client involvement. They ensure that a specified number of pods are always running and available. The entire update process is recorded, with versioning to provide options for pausing, resuming or rolling back to previous versions.
What Is Kubernetes StatefulSet?
A StatefulSet is a workload API object for managing stateful applications. Usually, Kubernetes users are not concerned with how pods are scheduled, although they do require pods to be deployed in order, to be attached to persistent storage volumes, and to have unique, persistent network IDs that are retained through rescheduling. StatefulSets can help achieve these objectives.
Like Deployments, StatefulSets manage the pods based on the same container specifications. However, they differ from deployments in that they maintain sticky identities for each pod. Pods may be created from an identical spec, but they are not interchangeable and are thus assigned unique identifiers that persist through rescheduling.
This article is part of our series about Kubernetes storage.
In this article:
- How Do Kubernetes Deployment and StatefulSets Work?
- Kubernetes StatefulSets vs Deployment: Use Cases and Examples
- Kubernetes Storage Optimization with Cloud Volumes ONTAP
How Do Kubernetes Deployment and StatefulSets Work?
Deployments allow you to manage sets of identical pods (or ReplicaSets) using common configurations. Once you’ve defined and deployed a Deployment, Kubernetes ensures that the pods it manages meet the requirements you’ve set. This provides granular control over the rollout of new pod versions and rollback to previous versions.
Deployments are typically used for stateless applications, but you can save a deployment’s state by attaching a persistent volume and making it stateful. All deployed pods share the same volume, with the same data.
The controller verifies if the current state matches the deployment’s desired set, and creates a ReplicaSet if necessary, which then creates the pods. The major components of a deployment are the deployment template, the persistent volumes and the service.
Related content: read our guide to Kubernetes Persistent Volumes
In a StatefulSet, each pod is given a name and treated individually, in contrast to a Kubernetes Deployment, where pods are easily replaceable. Stateful applications require pods with unique identities. This means that if any pod dies, it is immediately noticeable.
Every pod in a StatefulSet has two unique, stable identities (a network ID and a storage ID). The network ID enables the pod’s DNS name to persist across rescheduling (although the IP addresses may still change). The storage ID is retained regardless of the node the storage instance is rescheduled on. Persistent storage is required to enable the application to save the state and data across restarts.
StatefulSets serve as controllers, but they don’t create ReplicaSets—they create uniquely named pods, according to a specified pattern. The DNS name of a pod includes the ordinal index.
Each replica in a StatefulSet has its own state, with a unique persistent volume claim (PVC) created for each pod. For example, a StatefulSet with four replicas creates four pods, which each have their own volume, amounting to four PVCs.
StatefulSets require a headless service to return the IPs of the associated pods and enable direct interaction with them. The headless service has a service IP but no IP address and has to be created separately.
The major components of a StatefulSet are the set itself, the persistent volume and the headless service.
Here are the main differences between Deployments and StatefulSets:
- Deployments are used for stateless applications, StatefulSets for stateful applications
- The pods in a deployment are interchangeable, whereas the pods in a StatefulSet are not.
- Deployments require a service to enable interaction with pods, while a headless service handles the pods’ network ID in StatefulSets.
- In a deployment, the replicas all share a volume and PVC, while in a StatefulSet each pod has its own volume and PVC.
Kubernetes StatefulSets vs Deployment: Use Cases and Examples
Use a Deployment for Interchangeable Pods
Deployments are suited to cases where scaling up simply requires running more pods that are interchangeable.
For example, if you have a deployment of a Rust-based web application, traffic is routed to a single application instance by the load balancer at the front, which is provided via Kubernetes Services. The application retains all the state in its relational database, so you only need to request more copies if you want to scale up. The Kubernetes Deployment Controller will start instantly and create all the new pods.
The new pods have the same set of environment variables and ConfigMaps when booting, which presumably allows them to communicate with the database in the same way as the original pod.
The most appropriate use cases for deployments are stateless application workloads or cases that only require replicas of a single pod.
Use a StatefulSet for Unique Pods
StatefulSets are suitable for scaling stateful systems. For example, consider a relational database system behind your application with a deployment. You may want to scale up the app to build leader/follower topology based on consensus. However, you cannot implement a leader-election protocol for pods without identities.
When you scale a StatefulSet from one replica to three, for example, the StatefulSet controller will begin to deploy new (or missing) pods incrementally. The first pod will come up, initialize and finally settle into a “ready” state, followed by the second pod and so on.
A powerful feature of StatefulSets is the concept of PersistentVolumeClaim templates, which allow the provision of a unique persistent volume to each pod in a set. This is critical for replicating information such as the contents of a database.
The most appropriate use cases for StatefulSets include data services like key-value stores or databases, identity-sensitive systems like leader-election and consensus systems, or any workload that requires gradual roll-out.
Kubernetes Storage Optimization with Cloud Volumes ONTAP
NetApp Cloud Volumes ONTAP, the leading enterprise-grade storage management solution, delivers secure, proven storage management services on AWS, Azure and Google Cloud. Cloud Volumes ONTAP capacity can scale into the petabytes, and it supports various use cases such as file services, databases, DevOps or any other enterprise workload, with a strong set of features including high availability, data protection, storage efficiencies, Kubernetes integration, and more.
In particular, Cloud Volumes ONTAP supports Managing Stateful Applications in Kubernetes and Kubernetes Persistent Volume provisioning and management requirements of containerized workloads.
Learn more about how Cloud Volumes ONTAP helps to address the challenges of containerized applications in these Kubernetes Workloads with Cloud Volumes ONTAP Case Studies.