创建StatefulSet
功能介绍
This API is used to create a StatefulSet resource object.
URI
POST /apis/apps/v1/namespaces/{namespace}/statefulsets
参数 |
是否必选 |
描述 |
---|---|---|
namespace |
Yes |
Object name and auth scope, such as for teams and projects. |
pretty |
No |
If 'true', then the output is pretty printed. |
请求消息
请求参数:
请求参数如表2所示。
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
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. |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
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. |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
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 revision 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.具体请参见表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. |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
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. |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
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. |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
metadata |
Yes |
metadata object |
Standard object's metadata. |
spec |
Yes |
spec object |
Specification of the desired behavior of the pod. |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
rollingUpdate |
No |
rollingUpdate object |
RollingUpdate is used to communicate parameters when Type is RollingUpdateStatefulSetStrategyType. |
type |
No |
String |
Type indicates the type of the StatefulSetUpdateStrategy. |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
partition |
No |
Integer |
Partition indicates the ordinal at which the StatefulSet should be partitioned. |
请求示例:
{ "apiVersion": "apps/v1", "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": "nginx:alpine", "name": "statefulset-test" } ], "imagePullSecrets": [{ "name": "default-secret" }] } } } }
响应消息
响应参数:
响应参数的详细描述请参见表2
响应示例:
{ "kind": "StatefulSet", "apiVersion": "apps/v1", "metadata": { "name": "statefulset-test", "namespace": "development", "selfLink": "/apis/apps/v1/namespaces/development/statefulsets/statefulset-test", "uid": "0669a8ed-cc9e-44a9-a54c-ea90f94aa4ca", "resourceVersion": "16781", "generation": 1, "creationTimestamp": "2021-10-14T02:06:20Z", "labels": { "name": "statefulset-test" } }, "spec": { "replicas": 1, "selector": { "matchLabels": { "name": "statefulset-test" } }, "template": { "metadata": { "creationTimestamp": null, "labels": { "name": "statefulset-test" } }, "spec": { "containers": [ { "name": "statefulset-test", "image": "nginx:alpine", "resources": {}, "terminationMessagePath": "/dev/termination-log", "terminationMessagePolicy": "File", "imagePullPolicy": "IfNotPresent" } ], "restartPolicy": "Always", "terminationGracePeriodSeconds": 30, "dnsPolicy": "ClusterFirst", "securityContext": {}, "imagePullSecrets": [ { "name": "default-secret" } ], "schedulerName": "default-scheduler" } }, "serviceName": "service-test", "podManagementPolicy": "OrderedReady", "updateStrategy": { "type": "RollingUpdate", "rollingUpdate": { "partition": 0 } }, "revisionHistoryLimit": 10 }, "status": { "replicas": 0 } }
