Updating a StatefulSet

Function

This API is used to update a StatefulSet under a specified namespace.

The following fields can be updated:

  • metadata.labels
  • metadata.generateName
  • metadata.annotations
  • spec.replicas
  • spec.template
  • spec.restartPolicy
  • spec.revisionHistoryLimit
  • spec.progressDeadlineSeconds

URI

PATCH /apis/apps/v1beta1/namespaces/{namespace}/statefulsets/{name}

Table 1 describes the parameters of this API.

Table 1 Parameter description

Parameter

Mandatory

Description

name

Yes

Name of the StatefulSet.

namespace

Yes

Namespace to which the StatefulSet you want to update belongs.

pretty

No

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

Request

Request parameters

For the description about request parameters, see Table 2.

For the description about the Content-Type field, see Patch Request Method Operation Description.

Example request

Content-Type: application/merge-patch+json
{
    "metadata": {
        "labels": {
            "app": "mysql-0"
        }
    }
}

Response

Response parameters

For the description about response parameters, see Table 2.

Example response

{
    "kind": "StatefulSet", 
    "apiVersion": "apps/v1beta1", 
    "metadata": {
        "name": "statefulset-test", 
        "namespace": "8f6c39e7c269440c881bba2fc49586d6", 
        "selfLink": "/apis/apps/v1beta1/namespaces/8f6c39e7c269440c881bba2fc49586d6/statefulsets/statefulset-test", 
        "uid": "ee0ef0d0-2728-11e8-8930-84a9c46e8ca3", 
        "resourceVersion": "4510963", 
        "generation": 2, 
        "creationTimestamp": "2018-03-14T01:42:18Z", 
        "labels": {
            "app": "mysql-0", 
            "appgroup": ""
        }, 
        "annotations": {
            "description": ""
        }, 
        "enable": true
    }, 
    "spec": {
        "replicas": 2, 
        "selector": {
            "matchLabels": {
                "app": "statefulset-test"
            }
        }, 
        "template": {
            "metadata": {
                "creationTimestamp": null, 
                "labels": {
                    "app": "statefulset-test"
                }, 
                "annotations": {
                    "com.huawei.scheduler/container-type": "secure-container", 
                    "metrics.alpha.kubernetes.io/custom-endpoints": "[{api:'',path:'',port:'',names:''}]", 
                    "pod.alpha.kubernetes.io/initialized": "true"
                }, 
                "enable": true
            }, 
            "spec": {
                "containers": [
                    {
                        "name": "container-0", 
                        "image": "mysql:latest", 
                        "resources": {
                            "limits": {
                                "cpu": "1", 
                                "memory": "2Gi"
                            }, 
                            "requests": {
                                "cpu": "1", 
                                "memory": "2Gi"
                            }
                        }, 
                        "lifecycle": {}, 
                        "terminationMessagePath": "/dev/termination-log", 
                        "terminationMessagePolicy": "File", 
                        "imagePullPolicy": "IfNotPresent"
                    }, 
                    {
                        "name": "container-1", 
                        "image": "nginx:latest", 
                        "resources": {
                            "limits": {
                                "cpu": "1", 
                                "memory": "2Gi"
                            }, 
                            "requests": {
                                "cpu": "1", 
                                "memory": "2Gi"
                            }
                        }, 
                        "lifecycle": {}, 
                        "terminationMessagePath": "/dev/termination-log", 
                        "terminationMessagePolicy": "File", 
                        "imagePullPolicy": "Always"
                    }
                ], 
                "restartPolicy": "Always", 
                "terminationGracePeriodSeconds": 30, 
                "dnsPolicy": "ClusterFirst", 
                "securityContext": {}, 
                "imagePullSecrets": [
                    {
                        "name": "imagepull-secret"
                    }
                ], 
                "affinity": {}, 
                "schedulerName": "default-scheduler"
            }
        }, 
        "serviceName": "test", 
        "podManagementPolicy": "OrderedReady", 
        "updateStrategy": {
            "type": "RollingUpdate"
        }, 
        "revisionHistoryLimit": 10
    }, 
    "status": {
        "observedGeneration": 2, 
        "replicas": 1, 
        "currentReplicas": 1, 
        "currentRevision": "statefulset-test-2238135242", 
        "updateRevision": "statefulset-test-4168075007"
    }
}

Status Code

Table 2 describes the status code of this API.

Table 2 Status code

Status Code

Description

200

This operation succeeds, and a StatefulSet resource object is returned.

For more status codes, see Status Codes.