因为status是cr的subresource,所以不支持使用kubectl直接更新cr status,一般由controller来更新status。
在KubeBuilder框架中,使用xxx.Status().Update(xxx)方式来更新status。
创建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
crResourceVersion=`kubectl get fruit $crName -o jsonpath='{.metadata.resourceVersion}'`
json="{\"apiVersion\": \"crd.io/v1\", \"kind\": \"Fruit\", \"metadata\": {\"name\": \"$crName\", \"resourceVersion\": \"$crResourceVersion\"}, \"status\": {\"enable\": true}}"
curl -H "Content-Type: application/json" -X PUT -d "$json" http://127.0.0.1:8001/apis/crd.io/v1/fruits/$crName
kill `ps -ef | grep 'kubectl proxy' | grep -v grep | awk '{print $2}'`
标签:status,kubectl,crName,json,cr,curl From: https://www.cnblogs.com/WJQ2017/p/18401724