If you use kubectl, you may be aware that you cannot update the Custom Resource (CR) Status (GitHub issue).

However, you can achieve this with curl.

For this example, we’re going to use a CRD (Custom Resource Definition) called buildJob and a CR called build-job-asc, which has the following Status:

status:
  buildStatus: Scheduled

But we want to update it to the following:

status:
  buildStatus: Pending

The syntax for the curl command is:

curl -k $apiServer/apis/$apiVersion/namespaces/$namespace/$crd/$cr/status --header "Authorization: Bearer $TOKEN" -XPATCH -d"{\"status\":{$thingToChange}}" -H "Content-Type: application/merge-patch+json"

For our example, the curl command would be:

curl -k $apiServer/apis/k8s.test.io/v1alpha1/namespaces/default/buildjob/build-job-asc/status --header "Authorization: Bearer $TOKEN" -XPATCH -d'{"status":{"buildStatus": "Pending"}}' -H "Content-Type: application/merge-patch+json"

Working with the API Server with Minikube

The easiest way to access the Kubernetes API, when running minikube, is to use kubectl proxy --port=8080, which allows you to access the API with curl http://localhost:8080/api.

It also allows you to browse the API in your browser.

  • Start minikube using minikube start --extra-config=apiserver.Features.EnableSwaggerUI=true
  • Then start kubectl proxy and navigate to http://localhost:8080/swagger-ui/ in your browser.

Note: You can access the Kubernetes API with curl directly using curl --cacert ~/.minikube/ca.crt --cert ~/.minikube/client.crt --key ~/.minikube/client.key https://minikube ip:8443/api/, where minikube ip can be retrieved by running minikube ip, but usually there is no advantage in doing so. Common browsers are not happy with the certificates minikube generates, so if you want to access the API with your browser you need to use kubectl proxy.

References