Replacing a Secret

Function

This API is used to replace a specified secret.

The following fields can be updated:

  • metadata.labels
  • metadata.annotations
  • data
  • If type is set to Opaque, the key and value of data can be updated.
  • If type is not set to Opaque, only the value of data can be updated.

URI

PUT /api/v1/namespaces/{namespace}/secrets/{name}

Table 1 Path parameters

Parameter

Description

namespace

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

name

Name of the Secret.

Table 2 Query parameter

Parameter

Mandatory

Description

pretty

No

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

Request

Request parameters

For the description about request parameters, see Table 123.

Example request

Change the key2 of the secret created in Creating a Secret to test.

{
    "apiVersion": "v1",
    "kind": "Secret",
    "metadata": {
        "name": "secret-test"
    },
    "type": "Opaque",
    "data": {
        "key1": "MWYyZDFlMmU2N2Rm",
        "test": "dGVzdA=="
    }
}

Response

Response parameters

For the description about response parameters, see Table 123.

Example response

{
    "kind": "Secret",
    "apiVersion": "v1",
    "metadata": {
        "name": "secret-test",
        "namespace": "namespace-test",
        "selfLink": "/api/v1/namespaces/namespace-test/secrets/secret-test",
        "uid": "e6170b6d-aff6-11e8-8f17-c81fbe371a17",
        "resourceVersion": "5199399",
        "creationTimestamp": "2018-09-04T03:59:19Z",
        "enable": true
    },
    "data": {
        "key1": "MWYyZDFlMmU2N2Rm",
        "test": "dGVzdA=="
    },
    "type": "Opaque"
}

Status Code

Table 3 describes the status code of this API.

Table 3 Status code

Status Code

Description

200

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

For more status codes, see Status Codes.