• Cloud Container Engine

cce
  1. Help Center
  2. Cloud Container Engine
  3. API Reference 2.0
  4. Kubernetes API
  5. Service
  6. Updating a Specified Service

Updating a Specified Service

Function

This API is used to update a specified Service object.

The following fields can be updated:

  • metadata.selfLink
  • metadata.resourceVersion
  • metadata.generation
  • metadata.creationTimestamp
  • metadata.deletionTimestamp
  • metadata.labels
  • metadata.clusterName
  • metadata.generateName
  • metadata.annotations
  • spec.externalTrafficPolicy
  • spec.sessionAffinity
  • spec.type
    NOTE:

    The update priority of the value of spec.type is as follows: LoadBalancer > NodePort > ClusterIP. When spec.type is set to ClusterIP, it can be updated to LoadBalancer or NodePort; when spec.type is set to NodePort, it can be updated to LoadBalancer; when spec.type is set to LoadBalancer, it cannot be updated.

  • spec.port
  • spec.selector
  • spec.externalIPs
  • spec.loadBalancerIP
  • spec.loadBalancerSourceRanges

URI

PATCH /api/v1/namespaces/{namespace}/services/{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 Service.

Request

Request parameters:

For the description about the Content-Type message header, see section Patch Request Method Operation Description.

For the description about request parameters, see Table 2.

Example request:

Content-Type: application/strategic-merge-patch+json
 { 
     "spec": { 
         "ports": [ 
             { 
                 "name": "test1", 
                 "protocol": "TCP", 
                 "port": 8765, 
                 "targetPort": 9376 
             }, 
             { 
                 "name": "test2", 
                 "protocol": "TCP", 
                 "port": 8765, 
                 "targetPort": 9076 
             } 
         ], 
         "selector": { 
             "app": "example" 
         } 
     } 
 }

Response

Response parameters:

For the description about response parameters, see Table 2.

Example response:

{ 
   "kind": "Service", 
   "apiVersion": "v1", 
   "metadata": { 
     "name": "test", 
     "namespace": "default", 
     "selfLink": "/api/v1/namespaces/default/services/raoy", 
     "uid": "e0d681b7-5d17-11e6-aeb9-286ed488fafe", 
     "resourceVersion": "1602", 
     "creationTimestamp": "2016-08-08T03:26:21Z" 
   }, 
   "spec": { 
     "ports": [ 
       { 
         "name": "test1", 
         "protocol": "TCP", 
         "port": 8765, 
         "targetPort": 9376 
       }, 
       { 
         "name": "test2", 
         "protocol": "TCP", 
         "port": 8765, 
         "targetPort": 9076 
       } 
     ], 
     "selector": { 
       "app": "example" 
     }, 
     "clusterIP": "10.0.0.193", 
     "type": "ClusterIP", 
     "sessionAffinity": "None" 
   }, 
   "status": { 
     "loadBalancer": {} 
   } 
 }

Status Code

Table 2 describes the status code of this API.

Table 2 Status code

Status Code

Description

200

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

For the description about status codes, see section Status Codes.