Photo from the site Unsplash.com
Kubernetes - - — , , , . , , kubectl delete
, delete
Kubernetes , .
:
ConfigMaps kubectl. , , .
delete
Kubernetes , , . kubectl
: create
, get
, patch
delete
.
kubectl delete
:
$ kubectl create configmap mymap configmap/mymap created
$ kubectl get configmap/mymap NAME DATA AGE mymap 0 12s
$ kubectl delete configmap/mymap configmap "mymap" deleted
$ kubectl get configmap/mymap Error from server (NotFound): configmaps "mymap" not found
$
, . , kubectl create configmap mymap
, configmap mymap
. get
, . configmap. get
, HTTP 404, configmap .
delete
:
delete
, , -.
, Kubernetes - , .
— , , . , . , . , , . , .
, :
kubernetes.io/pv-protection
kubernetes.io/pvc-protection
. .
configmap , :
$ cat <<EOF | kubectl create -f - apiVersion: v1 kind: ConfigMap metadata: name: mymap finalizers: - kubernetes EOF
configmap , kubernetes
. configmap «», . configmap:
$ kubectl delete configmap/mymap & configmap "mymap" deleted jobs [1]+ Running kubectl delete configmap/mymap
Kubernetes , , , , . . get
, , deletionTimestamp
.
$ kubectl get configmap/mymap -o yaml apiVersion: v1 kind: ConfigMap metadata: creationTimestamp: "2020-10-22T21:30:18Z" deletionGracePeriodSeconds: 0 deletionTimestamp: "2020-10-22T21:30:34Z" finalizers: - kubernetes name: mymap namespace: default resourceVersion: "311456" selfLink: /api/v1/namespaces/default/configmaps/mymap uid: 93a37fed-23e3-45e8-b6ee-b2521db81638
, , . , Kubernetes , , read-only. , — . , , .
patch
. , . get
configmap, .
$ kubectl patch configmap/mymap \ --type json \ --patch='[ { "op": "remove", "path": "/metadata/finalizers" } ]' configmap/mymap patched [1]+ Done kubectl delete configmap/mymap $ kubectl get configmap/mymap -o yaml Error from server (NotFound): configmaps "mymap" not found
:
, , Kubectl. , Kubernetes .
(owner references) . , , , .
, . UID. UID. replica set, . deploy stateful set, replica set pod .
, . , . configmap , :
$ cat <<EOF | kubectl create -f - apiVersion: v1 kind: ConfigMap metadata: name: mymap-parent EOF $ export CM_UID=$(kubectl get configmap mymap-parent -o jsonpath="{.metadata.uid}") $ cat <<EOF | kubectl create -f - apiVersion: v1 kind: ConfigMap metadata: name: mymap-child ownerReferences: - apiVersion: v1 kind: ConfigMap name: mymap-parent uid: $CM_UID EOF
, , :
$ kubectl get configmap NAME DATA AGE mymap-child 0 12m4s mymap-parent 0 12m4s $ kubectl delete configmap/mymap-child configmap "mymap-child" deleted $ kubectl get configmap NAME DATA AGE mymap-parent 0 12m10s
configmap . , , , get
configmap, , configmap :
$ kubectl get configmap NAME DATA AGE mymap-child 0 10m2s mymap-parent 0 10m2s $ kubectl delete configmap/mymap-parent configmap "mymap-parent" deleted $ kubectl get configmap No resources found in default namespace.
, , . cascade
. cascade true
, --cascade=false kubectl delete
, , .
, . , --cascade=false, :
$ kubectl get configmap NAME DATA AGE mymap-child 0 13m8s mymap-parent 0 13m8s $ kubectl delete --cascade=false configmap/mymap-parent configmap "mymap-parent" deleted $ kubectl get configmap NAME DATA AGE mymap-child 0 13m21s
--cascade API, . API curl (propagation policy):
$ kubectl proxy --port=8080 & Starting to serve on 127.0.0.1:8080 $ curl -X DELETE \ localhost:8080/api/v1/namespaces/default/configmaps/mymap-parent \ -d '{ "kind":"DeleteOptions", "apiVersion":"v1", "propagationPolicy":"Background" }' \ -H "Content-Type: application/json" { "kind": "Status", "apiVersion": "v1", "metadata": {}, "status": "Success", "details": { ... } }
kubectl — API. , API , curl
URL, delete
.
:
Foreground
: ( ).Background
: ( ).Orphan
: .
, , . , . , , .
: , - , , , finalize
. , :
$ cat <<EOF | curl -X PUT \ localhost:8080/api/v1/namespaces/test/finalize \ -H "Content-Type: application/json" \ --data-binary @- { "kind": "Namespace", "apiVersion": "v1", "metadata": { "name": "test" }, "spec": { "finalizers": null } } EOF
, , , Kubernetes . , , .
, Kubernetes, . , , . , . , , API . , Kubernetes, -.
: