Replacing a Specified Secret

Function

This API is used to replace the secret in a specified namespace.

The following fields can be updated:

  • metadata.selfLink
  • metadata.resourceVersion
  • metadata.labels
  • metadata.clusterName
  • metadata.generateName
  • metadata.annotations
  • When type is set to Opaque, the key and value of data can be updated.
  • When type is not set to Opaque, only the value of data can be updated.

URI

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

Table 1 describes the parameters of this API.

Table 1 Parameter description

Parameter

Mandatory

Description

pretty

No

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

namespace

Yes

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

name

Yes

Name of the secret.

Request

Request parameters:

For the description about request parameters, see Table 2.

Example request:

{ 
   "apiVersion": "v1", 
   "kind": "Secret", 
   "metadata": { 
     "name": "mysecret" 
   }, 
   "type": "Opaque", 
   "data": { 
     "password": "******", #Encoded using Base64. Method: echo -n "to-be-encoded content" | base64
     "username": "*****" #Encoded using Base64. Method: echo -n "to-be-encoded content" | base64
   } 
 }

Response

Response parameters:

For the description about response parameters, see Table 2.

Example Response:

{
    "kind": "Secret",
    "apiVersion": "v1",
    "metadata": {
        "name": "mysecret",
        "namespace": "ns-12130306-s",
        "selfLink": "/api/v1/namespaces/ns-12130306-s/secrets/mysecret",
        "uid": "0bbfb314-dfb3-11e7-9c19-fa163e2d897b",
        "resourceVersion": "418375",
        "creationTimestamp": "2017-12-13T03:09:34Z",
        "enable": true
    },
    "data": {
        "password": "******",
        "username": "*****" 
    },
    "type": "Opaque",
    "httpcode": 200,
    "header": {
        "X-Frame-Options": "SAMEORIGIN",
        "Strict-Transport-Security": "max-age=31536000; includeSubdomains;",
        "Server": "Web Server",
        "X-Router-Status": "fresh,upstream return 200",
        "X-Content-Type-Options": "nosniff",
        "Connection": "keep-alive",
        "X-Download-Options": "noopen",
        "Set-Cookie": "******; Expires=Thu, 14-Dec-17 03:09:34 GMT; Domain=192.168.50.250; Path=/; Secure; HttpOnly",
        "Content-Length": "364",
        "X-XSS-Protection": "1; mode=block;",
        "Date": "Wed, 13 Dec 2017 03:09:34 GMT",
        "Content-Type": "application/json"
    }
}

Status Code

Table 2 describes the status code of this API.

Table 2 Status code

Status Code

Description

200

If the operation is successful, the updated secret is returned.

For the description about error status codes, see Status Code.