Replacing a Pod

Function

This API is used to replace a specified pod.

The following fields can be updated:

  • metadata.labels
  • metadata.annotations
  • spec.initContainers[*].image
  • spec.containers[*].image
  • spec.activeDeadlineSeconds
  • spec.tolerations.tolerationSeconds

Other fields cannot be updated.

URI

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

Table 1 Path parameters

Parameter

Description

namespace

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

name

Name of the Pod.

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 2.

Example request

Replace the pod image created in Creating a Pod with redis:latest.

{
    "apiVersion": "v1",
    "kind": "Pod",
    "metadata": {
        "labels": {
            "name": "pod-test"
        },
        "name": "pod-test"
    },
    "spec": {
        "containers": [
            {
                "image": "redis:latest",
                "imagePullPolicy": "Always",
                "name": "test",
                "resources": {
                    "requests": {
                        "cpu": "0.5",
                        "memory": "1024Mi"
                    },
                    "limits": {
                        "cpu": "0.5",
                        "memory": "1024Mi"
                    }
                }
            }
        ],
        "imagePullSecrets": [
            {
                "name": "imagepull-secret"
            }
        ],
        "restartPolicy": "Always"
    }
}

Response

Response parameters

For the description about response parameters, see Table 2.

Example response

{
    "kind": "Pod",
    "apiVersion": "v1",
    "metadata": {
        "name": "pod-test",
        "namespace": "namespace-test",
        "selfLink": "/api/v1/namespaces/namespace-test/pods/pod-test",
        "uid": "3b99abe8-b032-11e8-9d5d-c88d83be759f",
        "resourceVersion": "5253248",
        "creationTimestamp": "2018-09-04T11:04:02Z",
        "labels": {
            "name": "pod-test"
        },
        "enable": true
    },
    "spec": {
        "containers": [
            {
                "name": "test",
                "image": "redis:latest",
                "resources": {
                    "limits": {
                        "cpu": "500m",
                        "memory": "1Gi"
                    },
                    "requests": {
                        "memory": "1Gi",
                        "cpu": "500m"
                    }
                },
                "terminationMessagePath": "/dev/termination-log",
                "terminationMessagePolicy": "File",
                "imagePullPolicy": "Always"
            }
        ],
        "restartPolicy": "Always",
        "terminationGracePeriodSeconds": 30,
        "dnsPolicy": "ClusterFirst",
        "securityContext": {},
        "imagePullSecrets": [
            {
                "name": "imagepull-secret"
            }
        ],
        "schedulerName": "default-scheduler",
        "tolerations": [
            {
                "key": "node.kubernetes.io/not-ready",
                "operator": "Exists",
                "effect": "NoExecute",
                "tolerationSeconds": 300
            },
            {
                "key": "node.kubernetes.io/unreachable",
                "operator": "Exists",
                "effect": "NoExecute",
                "tolerationSeconds": 300
            }
        ]
    },
    "status": {
        "phase": "Running",
        "conditions": [
            {
                "type": "Initialized",
                "status": "True",
                "lastProbeTime": null,
                "lastTransitionTime": "2018-09-04T11:04:03Z"
            },
            {
                "type": "Ready",
                "status": "True",
                "lastProbeTime": null,
                "lastTransitionTime": "2018-09-04T11:04:36Z"
            },
            {
                "type": "PodScheduled",
                "status": "True",
                "lastProbeTime": null,
                "lastTransitionTime": "2018-09-04T11:04:02Z"
            }
        ],
        "hostIP": "192.149.117.100",
        "podIP": "192.168.244.170",
        "startTime": "2018-09-04T11:04:03Z",
        "containerStatuses": [
            {
                "name": "test",
                "state": {
                    "running": {
                        "startedAt": "2018-09-04T11:04:23Z"
                    }
                },
                "lastState": {},
                "ready": true,
                "restartCount": 0,
                "image": "redis",
                "imageID": "docker-pullable://redis@sha256:3ab7046bd035a47aa06963d8240651d00b57e82dab07ba374ad01f84dfa1230c",
                "containerID": "docker://f867ab7d5c68a86fc695e4d3e5f1912fdb8f98f5029ca96032b4d5d407d9a75c"
            }
        ],
        "qosClass": "Guaranteed",
        "managementIP": "172.28.0.17"
    }
}

Status Code

Table 3 describes the status code of this API.

Table 3 Status code

Status Code

Description

200

This operation succeeds, and the JSON of a Pod object is returned.

For more status codes, see Status Codes.