Replacing a Specified Service
Function
This API is used to replace a specified service.
The following fields can be updated:
- metadata.selfLink
- metadata.resourceVersion
- metadata.labels
- metadata.clusterName
- metadata.generateName
- metadata.annotations
- spec.externalTrafficPolicy
- spec.sessionAffinity
- spec.type
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
PUT /api/v1/namespaces/{namespace}/services/{name}
Table 1 describes the parameters of this API.
Request
Request parameters:
For the description about request parameters, see Table 2.
Example request:
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "myapp",
"resourceVersion": "683"
},
"spec": {
"ports": [{
"port": 80,
"targetPort": 80
}],
"selector": {
"app": "example"
},
"clusterIP": "10.0.0.139"
}
}
Response
Response parameters:
For the description about response parameters, see Request.
Example response:
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "myapp",
"namespace": "default",
"selfLink": "/api/v1/namespaces/default/services/myapp",
"uid": "58b5ca7c-5d12-11e6-aeb9-286ed488fafe",
"resourceVersion": "1204",
"creationTimestamp": "2016-08-08T02:46:46Z"
},
"spec": {
"ports": [
{
"protocol": "TCP",
"port": 80,
"targetPort": 80
}
],
"selector": {
"app": "example"
},
"clusterIP": "10.0.0.139",
"type": "ClusterIP",
"sessionAffinity": "None"
},
"status": {
"loadBalancer": {}
}
}
Status Code
Table 2 describes the status code of this API.
|
Status Code |
Description |
|---|---|
|
200 |
This operation succeeds, and a Service resource object is returned. |
For the description about error status codes, see Status Code.
Last Article: Obtaining a Specified Service
Next Article: Listing Services in a Specified Namespace
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.