curl命令更新k8s cr status
因为status是cr的subresource,所以不支持使用kubectl直接更新cr status,一般由controller来更新status。
在KubeBuilder框架中,使用xxx.Status().Update(xxx)方式来更新status。
cluster cr
创建crd和cr
cat <<EOF | kubectl create -f -
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: fruits.crd.io
spec:
group: crd.io
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
location:
type: string
status:
type: object
properties:
enable:
type: boolean
scope: Cluster
names:
plural: fruits
singular: fruit
kind: Fruit
EOF
cat <<EOF | kubectl create -f -
apiVersion: crd.io/v1
kind: Fruit
metadata:
name: apple
spec:
location: "beijing"
EOF
修改cluster粒度cr status
kubectl proxy &
crName=apple
curl -H "Content-Type: application/merge-patch+json" -XPATCH -d '{"status":{"enable":true}}' http://127.0.0.1:8001/apis/crd.io/v1/fruits/$crName
kill `ps -ef | grep 'kubectl proxy' | grep -v grep | awk '{print $2}'`
namespace cr
把scope从Cluster改成Namespaced,cr中增加namespace: default。
crName=apple
namespace=default
curl -H "Content-Type: application/merge-patch+json" -XPATCH -d '{"status":{"enable":true}}' http://127.0.0.1:8001/apis/crd.io/v1/namespaces/$namespace/fruits/$crName