replace
Replace a pod using the data in pod.json
kubectl replace -f ./pod.json
Replace a pod based on the JSON passed into stdin
cat pod.json | kubectl replace -f -
Update a single-container pod’s image version (tag) to v4
kubectl get pod mypod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -
Force replace, delete and then re-create the resource
kubectl replace --force -f ./pod.json
Replace a resource by file name or stdin.
JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by
$ kubectl get TYPE NAME -o yaml
Usage
$ kubectl replace -f FILENAME
Flags
Name | Shorthand | Default | Usage |
---|---|---|---|
allow-missing-template-keys | true | If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. | |
cascade | background | Must be “background”, “orphan”, or “foreground”. Selects the deletion cascading strategy for the dependents (e.g. Pods created by a ReplicationController). Defaults to background. | |
dry-run | none | Must be “none”, “server”, or “client”. If client strategy, only print the object that would be sent, without sending it. If server strategy, submit server-side request without persisting the resource. | |
field-manager | kubectl-replace | Name of the manager used to track field ownership. | |
filename | f | [] | to use to replace the resource. |
force | false | If true, immediately remove resources from API and bypass graceful deletion. Note that immediate deletion of some resources may result in inconsistency or data loss and requires confirmation. | |
grace-period | -1 | Period of time in seconds given to the resource to terminate gracefully. Ignored if negative. Set to 1 for immediate shutdown. Can only be set to 0 when —force is true (force deletion). | |
kustomize | k | Process a kustomization directory. This flag can’t be used together with -f or -R. | |
output | o | Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file. | |
raw | Raw URI to PUT to the server. Uses the transport specified by the kubeconfig file. | ||
recursive | R | false | Process the directory used in -f, —filename recursively. Useful when you want to manage related manifests organized within the same directory. |
save-config | false | If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future. | |
show-managed-fields | false | If true, keep the managedFields when printing objects in JSON or YAML format. | |
template | Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. | ||
timeout | 0s | The length of time to wait before giving up on a delete, zero means determine a timeout from the size of the object | |
validate | true | If true, use a schema to validate the input before sending it | |
wait | false | If true, wait for resources to be gone before returning. This waits for finalizers. |
当前内容版权归 Kubernetes 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Kubernetes .