Kubernetes v1 Workload resources are fundamental API objects that manage and orchestrate containerized applications within a cluster. These resources define how applications run, scale, and recover from failures. Key workload resources include Pods, Deployments, StatefulSets, DaemonSets, Jobs, and CronJobs, each designed to handle different workload patterns, ensuring reliability, scalability, and maintainability in Kubernetes environments.
Authentication
Add API authentication details
Readme
User instructions for this resource
The StatefulSet template is designed to define and manage a set of Pods with unique, persistent identities and stable hostnames in a Kubernetes cluster. It uses a combination of facets and variables to allow for flexible configurations.
Variables
: This global variable represents the identifier for the StatefulSet, used to access specific fields in the request values.__STS_ID__
: This variable is used specifically for the serviceAccountName field, allowing reference to a separate ServiceAccount resource.__SA_ID__
Collection Breakdown
- Base
{
"kind": "StatefulSet",
"facets": ["master"],
"metadata": "{{ __STS_ID__.metadata }}",
"apiVersion": "apps/v1"
}
This section is always included (due to the master facet). It sets the kind, apiVersion, and metadata for the StatefulSet resource.
- Spec
{
"spec": {
"replicas": "{{ __STS_ID__.spec.replicas }}",
"selector": "{{ __STS_ID__.spec.selector }}",
"serviceName": "{{ __STS_ID__.spec.serviceName }}"
},
"facets": ["addon:spec"]
}
This section defines the core spec for the StatefulSet, including replicas, selector, and the associated service name.
- Pod Template
{
"spec": {
"template": {
"spec": {
"containers": "{{ __STS_ID__.spec.template.spec.containers }}"
},
"metadata": "{{ __STS_ID__.spec.template.metadata }}"
}
},
"facets": ["addon:spec", "addon:podtemplate"]
}
This section defines the pod template, including containers and metadata.
- Volume Claim Templates
{
"spec": {
"volumeClaimTemplates": "{{ __STS_ID__.spec.volumeClaimTemplates }}"
},
"facets": ["addon:spec", "addon:volumeclaimtemplates"]
}
This section is unique to StatefulSets and defines the persistent volume claims for each pod.
Design Decisions
Modularity: The template is divided into multiple sections with separate facets, allowing users to include only the necessary parts of a StatefulSet definition.
StatefulSet-Specific Features: The template includes StatefulSet-specific features like serviceName and volumeClaimTemplates, which are crucial for maintaining stable network identities and persistent storage.
Comprehensive Pod Specification: The template includes a detailed pod template specification, allowing for fine-grained control over the pods created by the StatefulSet.
Flexibility in Storage Configuration: The volumeClaimTemplates section allows for flexible configuration of persistent storage for each pod in the StatefulSet.
Integration with Other Resources: The template allows for integration with other Kubernetes resources, such as ServiceAccounts, through dedicated variables.
Examples
Check Request Body tab section to play around with interactive examples.
Install(
)Example
The Curl tab in the request section below provides the curl command for your resource.
curl -X POST "https://configfacets.com/apis/repos/kubernetes/workload-resources/v1/resources/collections/statefulset/exec?format=json" -d '{"facets":["master","addon:spec","addon:podtemplate","addon:volumeclaimtemplates"],"values":{"basic_statefulset":{"spec":{"replicas":3,"selector":{"matchLabels":{"app":"nginx"}},"template":{"spec":{"containers":[{"name":"nginx","image":"nginx:1.14.2","ports":[{"name":"web","containerPort":80}],"volumeMounts":[{"name":"www","mountPath":"/usr/share/nginx/html"}]}]},"metadata":{"labels":{"app":"nginx"}}},"serviceName":"nginx","volumeClaimTemplates":[{"spec":{"resources":{"requests":{"storage":"1Gi"}},"accessModes":["ReadWriteOnce"]},"metadata":{"name":"www"}}]},"metadata":{"name":"web","namespace":"default"}}},"globalvars":{"__STS_ID__":"basic_statefulset"}}' | kubectl apply -f -