Kubernetes Rest API call equivalent to kubectl replace -f POD.yaml --force

7/16/2020

I am deploying plain pod yaml file. Attached is the snapshot of Pod.

My requirement is I want to update entire pod whenever its required. This can be achieved by using kubectl replace command with force, it will take care of deleting and re-creating it.

Command is kubectl replace -f pod.yaml --force.

The RestAPI for replace is PUT (https://kubernetes-url/api/v1/namespaces/default/pods/test-pod) What query parameter I need to pass to achieve force replace through rest api similar to kubectl force replace. enter image description here

-- Jayashree Madanala
kubectl
kubernetes
kubernetes-pod

1 Answer

7/16/2020

When you use --force internally it deletes the pod and create it again. PUT verb is not used in this case and there is no parameter for force in the REST API. You need to make two REST API call

  1. First with DELETE verb to https://kubernetes-url/api/v1/namespaces/default/pods/test-pod

  2. Second with POST verb to https://kubernetes-url/api/v1/namespaces/default/pods/test-pod

You can verify what REST API call is being made by running the command in verbose mode.

kubectl replace -f pod.yaml --force --v=8
-- Arghya Sadhu
Source: StackOverflow