I have CRD definition in Kubernetes. When I try to send a request with kubectl proxy
by this link curl http://localhost:8090/apis/sparkoperator.k8s.io/v1alpha1/namespaces/default/sparkapplications/
I get created custom object information. However, when I try to get the status of this custom object with curl http://localhost:8090/apis/sparkoperator.k8s.io/v1alpha1/namespaces/default/sparkapplications/status
I get an error:
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "sparkapplications.sparkoperator.k8s.io \"status\" not found",
"reason": "NotFound",
"details": {
"name": "status",
"group": "sparkoperator.k8s.io",
"kind": "sparkapplications"
},
"code": 404
Why there is no status for the custom object? Is there something wrong with CRD definition?
I use Minikube version v0.32.0 which I start this way:
minikube start --kubernetes-version v1.13.0 --memory 8048 --cpus 3 --feature-gates=CustomResourceSubresources=true
CRD definition looks like this:
apiVersion: sparkoperator.k8s.io/v1alpha1
kind: SparkApplication
metadata:
name: spark-example
namespace: default
spec:
type: Scala
image: gcr.io/ynli-k8s/spark:v2.4.0-SNAPSHOT
mainClass: org.apache.spark.examples.SparkExample
mainApplicationFile: http://localhost:8089/spark_k8s_airflow.jar
mode: cluster
deps: {}
driver:
coreLimit: 1000m
cores: 0.1
labels:
version: 2.4.0
memory: 1024m
serviceAccount: default
executor:
cores: 1
instances: 1
labels:
version: 2.4.0
memory: 1024m
imagePullPolicy: Always
subresources:
status: {}
UPDATE: I have called the object spark-example specifically, the object data is returned, but the status call returns error.
curl http://localhost:8090/apis/sparkoperator.k8s.io/v1alpha1/namespaces/default/sparkapplications/spark-example/status
returns this message:
the server could not find the requested resource
Although, there is subresources definition in the CRD definition.
curl http://localhost:8090/apis/sparkoperator.k8s.io/v1alpha1/namespaces/default/sparkapplications/
The above request will give you the list of SparkApplication
kind objects in default
namespaces.
To get specific object, you have to specify the object name:
curl http://localhost:8090/apis/sparkoperator.k8s.io/v1alpha1/namespaces/default/sparkapplications/<object-name>
status
is the part of the object, not SparkApplication
kind. That's why you are getting that error. If you try for specific object, it will work.
curl http://localhost:8090/apis/sparkoperator.k8s.io/v1alpha1/namespaces/default/sparkapplications/<object-name>/status
Note: I am assuming that you enabled
status
subresource forSparkApplication
CRD. Otherwise it will give error.
If status
subresource is not enabled in CRD definition, then you can not get status in /status
subpath. This is the feature of subresource.
How to know whether status
subresource enabled or not:
Check CRD yaml:
$ kubectl get crds/foos.try.com -o yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: foos.try.com
spec:
group: try.com
version: v1alpha1
scope: Namespaced
subresources:
status: {}
names:
plural: foos
singular: foo
kind: Foo
If CRD has following field under spec
, then status
subresource is enabled.
subresources:
status: {}