Creating a StatefulSet
Function
This API is used to create a StatefulSet resource object.
URI
POST /apis/apps/v1/namespaces/{namespace}/statefulsets (for clusters of v1.9 and later)
POST /apis/apps/v1beta1/namespaces/{namespace}/statefulsets (for clusters of v1.15 and earlier)
Table 1 describes the parameters of this API.
Request
Request parameters:
For the description about request parameters, see Table 2.
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
apiVersion |
Yes |
String |
apiVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. |
|
kind |
Yes |
String |
kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. |
|
metadata |
Yes |
metadata object |
Standard list metadata. |
|
spec |
Yes |
spec object |
Spec defines the desired identities of pods in this set. |
|
status |
No |
status object |
status is the current status of pods in this StatefulSet. This data may be out of date by some window of time. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
observedGeneration |
No |
Integer |
Most recent generation observed by this autoscaler. |
|
replicas |
No |
Integer |
replicas is the number of actual replicas. |
|
currentReplicas |
No |
Integer |
currentReplicas is the number of Pods created by the StatefulSet controller from the StatefulSet version indicated by currentRevision. |
|
currentRevision |
No |
String |
currentRevision, if not empty, indicates the version of the StatefulSet used to generate Pods in the sequence [0,currentReplicas). |
|
readyReplicas |
No |
Integer |
readyReplicas is the number of pods created by the StatefulSet controller that have a Ready Condition. |
|
updateRevision |
No |
String |
updateRevision, if not empty, indicates the version of the StatefulSet used to generate pods in the sequence [replicas-updatedReplicas,replicas). |
|
updatedReplicas |
No |
Integer |
updatedReplicas is the number of pods created by the StatefulSet controller from the StatefulSet version indicated by updateRevision. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
replicas |
No |
Integer |
replicas is the desired number of replicas of the given template. These are replicas in the sense that they are instantiations of the same Template, but individual replicas also have a consistent identity. If unspecified, defaults to 1. |
|
podManagementPolicy |
No |
String |
podManagementPolicy controls how pods are created during initial scale-up, when replacing pods on nodes, or when scaling down. The default policy is OrderedReady, where pods are created in increasing order (pod-0, then pod-1, etc) and the controller will wait until each pod is ready before continuing. When scaling down, the pods are removed in the opposite order. The alternative policy is Parallel which will create pods in parallel to match the desired scale without waiting, and on scale down will delete all pods at once. |
|
revisionHistoryLimit |
No |
Integer |
revisionHistoryLimit is the maximum number of revisions that will be maintained in the StatefulSet's change history. The revision history consists of all revisions not represented by a currently applied StatefulSetSpec version. The default value is 10. |
|
updateStrategy |
No |
updateStrategy object |
updateStrategy indicates the StatefulSetUpdateStrategy that will be employed to update pods in the StatefulSet when a revision is made to Template. |
|
serviceName |
Yes |
String |
serviceName is the name of the service that governs this StatefulSet. This service must exist before the StatefulSet, and is responsible for the network identity of the set. Pods get DNS/hostnames that follow the pattern: pod-specific-string.serviceName.default.svc.cluster.local where "pod-specific-string" is managed by the StatefulSet controller. |
|
volumeClaimTemplates |
No |
Object |
volumeClaimTemplates is a list of claims that pods are allowed to reference. The StatefulSet controller is responsible for mapping network identities to claims in a way that maintains the identity of a pod. Every claim in this list must have at least one matching (by name) volumeMount in one container in the template. A claim in this list takes precedence over any volumes in the template, with the same name. For details, see Table 2. |
|
selector |
Yes |
selector object |
Selector is a label query over pods that should match the replica count. If empty, defaulted to labels on the pod template. |
|
template |
Yes |
PodTemplateSpec object |
Template is the object that describes the pod that will be created if insufficient replicas are detected. Each pod stamped out by the StatefulSet will fulfill this Template, but have a unique identity from the rest of the StatefulSet. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
matchExpressions |
No |
matchExpressions object |
matchExpressions is a list of label selector requirements. The requirements are ANDed. |
|
matchLabels |
No |
Object |
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
key |
No |
String |
key is the label key that the selector applies to. |
|
operator |
No |
String |
operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist. |
|
values |
No |
String |
values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
metadata |
Yes |
metadata object |
Standard object's metadata. |
|
spec |
Yes |
spec object |
Specification of the desired behavior of the pod. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
rollingUpdate |
No |
rollingUpdate object |
rollingUpdate is used to communicate parameters when Type is RollingUpdateStatefulSetStrategyType. |
|
type |
No |
String |
type indicates the type of the StatefulSetUpdateStrategy. |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
partition |
No |
Integer |
partition indicates the ordinal at which the StatefulSet should be partitioned. |
Example request:
{
"apiVersion": "apps/v1beta1",
"kind": "StatefulSet",
"metadata": {
"labels": {
"name": "statefulset-test"
},
"name": "statefulset-test"
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"name": "statefulset-test"
}
},
"serviceName": "service-test",
"template": {
"metadata": {
"labels": {
"name": "statefulset-test"
}
},
"spec": {
"containers": [
{
"image": "172.16.5.235:20202/test/nginx",
"name": "statefulset-test"
}
],
"imagePullSecrets": [{
"name": "default-secret"
}]
}
}
}
}
Response
Response parameters:
For the description about response parameters, see Table 2.
Example response:
{
"kind": "StatefulSet",
"apiVersion": "apps/v1beta1",
"metadata": {
"name": "statefulset-test",
"namespace": "default",
"selfLink": "/apis/apps/v1beta1/namespaces/default/statefulsets/statefulset-test",
"uid": "d9e1118c-fc20-11e7-9c3c-fa163eb8ad1a",
"resourceVersion": "486277",
"generation": 1,
"creationTimestamp": "2018-01-18T07:26:08Z",
"labels": {
"name": "statefulset-test"
},
"enable": true
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"name": "statefulset-test"
}
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"name": "statefulset-test"
},
"enable": true
},
"spec": {
"containers": [
{
"name": "statefulset-test",
"image": "172.16.5.235:20202/test/nginx",
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"imagePullPolicy": "Always"
}
],
"restartPolicy": "Always",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"securityContext": {},
"imagePullSecrets": [
{
"name": "default-secret"
}
],
"schedulerName": "default-scheduler"
}
},
"serviceName": "service-test",
"podManagementPolicy": "OrderedReady",
"updateStrategy": {
"type": "OnDelete"
},
"revisionHistoryLimit": 10
},
"status": {
"replicas": 0
}
}
Status Code
Table 10 describes the status code of this API.
|
Status Code |
Description |
|---|---|
|
201 |
The request has been fulfilled, resulting in the creation of a new resource. |
For the description about error status codes, see Status Code.
Last Article: StatefulSet
Next Article: Deleting a Specified StatefulSet
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.