文档首页 > > API参考> Kubernetes API> StatefulSet> 创建StatefulSet

创建StatefulSet

分享
更新时间:2020/09/18 GMT+08:00

功能介绍

This API is used to create a StatefulSet resource object.

URI

POST /apis/apps/v1/namespaces/{namespace}/statefulsets (Supports 1.9 and 1.9+)

POST /apis/apps/v1beta1/namespaces/{namespace}/statefulsets (Supports 1.15 and 1.15-)

表1描述该API的参数。

表1 参数解释

参数

是否必选

描述

namespace

Yes

Object name and auth scope, such as for teams and projects.

pretty

No

If 'true', then the output is pretty printed.

请求消息

请求参数:

请求参数如表2所示。

表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.

表3 status字段数据结构说明

参数

是否必选

参数类型

描述

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.

表4 spec字段数据结构说明

参数

是否必选

参数类型

描述

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.

表5 selector字段数据结构说明

参数

是否必选

参数类型

描述

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.

表6 matchExpressions字段数据结构说明

参数

是否必选

参数类型

描述

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.

表7 PodTemplateSpec字段数据结构说明

参数

是否必选

参数类型

描述

metadata

Yes

metadata object

Standard object's metadata.

spec

Yes

spec object

Specification of the desired behavior of the pod.

表8 updateStrategy字段数据结构说明

参数

是否必选

参数类型

描述

rollingUpdate

No

rollingUpdate object

RollingUpdate is used to communicate parameters when Type is RollingUpdateStatefulSetStrategyType.

type

No

String

Type indicates the type of the StatefulSetUpdateStrategy.

表9 rollingUpdate字段数据结构说明

参数

是否必选

参数类型

描述

partition

No

Integer

Partition indicates the ordinal at which the StatefulSet should be partitioned.

请求示例:

{
    "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"
                }]
            }
        }
    }
}

响应消息

响应参数:

响应参数的详细描述请参见表2

响应示例:

{
    "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
    }
}

状态码

表10描述API的状态码。

表10 状态码

状态码

描述

201

The request has been fulfilled, resulting in the creation of a new resource.

异常状态码请参见状态码

分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!非常感谢您的反馈,我们会继续努力做到更好!
反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

智能客服提问云社区提问