Kubernetes Rest API to change existing secret/configmap in Pod

4/8/2020

I have deployed Pod using kubernetes Rest API POST /api/v1/namespaces/{namespace}/pods The request body has the podspec with volumes something as below:

{
 "kind": "Pod",
  "apiVersion": "v1",
  "metadata": {
    "name": "test",
    "namespace": "default"
  },
  "spec": {
    "volumes": [
            {
                "name": "test-secrets",
                "secret": {
                    "secretName": "test-secret-one"
                }
            }
        ],
"containers":[
<<container json>>.........
]
  }
}
  1. Now I want to change the secret name test-secret-one to test-secret-two for the Pod?

  2. How can I achieve this? And what Rest API I need to use?

  3. Patch rest API - I can use the change container image but cant be used for Volumes. If this can be used Can you give me an example or reference?

  4. Is there any Kubernetes Rest API to restart the Pod. Note that we are not using a deployment object model. It is directly deployed as Pod, not as deployment.

Can anyone help here?

-- Jayashree Madanala
kubernetes
kubernetes-pod
rest

1 Answer

4/16/2020

I'm posting the answer as Community Wiki as solution came from @Matt in the comments.

Volumes aren't updatable fields, you will need to recreate the pod with the new spec.

The answer to most of your questions is use a deployment and patch it. The deployment will manage the updates and restarts for you.

A different approach is also possible and was suggested by @Kitt:

If you only update the content of Secrets and Configmap instead of renaming them, the mounted volumes will be refreshed by kubelet in the duration --sync-frequency(1m as default).

-- mWatney
Source: StackOverflow