jkube resource failed: Unknown type CRD

251 views Asked by At

I am using jkube to deploy a springboot helloworld application on my kubernetes installation. I wanted to add a resource fragment defining a Traefik ingress route but k8s:resource fails with "Unknown type 'ingressroute'".
IngressRoute has already been defined on the cluster using custom resource definition.

How do I write my fragment?

The following works when i deploy it with kubectl.

# IngresRoute
---
kind: IngressRoute
apiVersion: traefik.containo.us/v1alpha1
metadata:
  name: demo
  namespace: default

spec:
  entryPoints: 
    - web
  routes:
  - match: Host(`demo.domainname.com`)
    kind: Rule
    services:
    - name: demo
      port: 80
2

There are 2 answers

0
Rohan Kumar On

I'm from Eclipse JKube team. We have improved CustomResource support a lot in our recent v1.2.0 release. Now you only need to worry about how you name your CustomResource fragment and Eclipse JKube would detect the CustomResourceDefinition for specified IngressRoute.

I think you would need to name CustomResource fragments with a *-cr.yml at the end. This is due to distinguishing them from standard Kubernetes resources. For example I added your IngressRoute fragment in my src/main/jkube like this:

jkube-custom-resource-fragments : $ ls src/main/jkube/
ats-crd.yml  crontab-crd.yml  dummy-cr.yml         podset-crd.yaml      traefic-crd.yaml
ats-cr.yml   crontab-cr.yml   ingressroute-cr.yml  second-dummy-cr.yml  traefic-ingressroute2-cr.yml
crd.yaml     dummy-crd.yml    istio-crd.yaml       test2-cr.yml         virtualservice-cr.yml
jkube-custom-resource-fragments : $ ls src/main/jkube/traefic-ingressroute2-cr.yml 
src/main/jkube/traefic-ingressroute2-cr.yml

Then you should be able to see your IngressRoute generated after k8s:resource phase:

$ mvn k8s:resource
...
$ cat target/classes/META-INF/jkube/kubernetes.yml

You can then go ahead and apply these generated manifests to your Kubernetes Cluster with apply goal:

$ mvn k8s:apply
...
$ kubectl get ingressroute
NAME   AGE
demo   17s
foo    16s

I tried all this on this reproducer project and it seemed to be working okay for me: https://github.com/r0haaaan/jkube-custom-resource-fragments

0
msteff On

@Rohan Kumar

Thank you for your answer. I can built and deploy it, but as soon as I add a file to use my IngressRoute, then the k8s:resource target fails.

I added files - one for each CRD with filename -cr.yml and added the following to the pom file:

<pre>
<resources>
    <customResourceDefinitions>
        <customResourceDefinition>traefikservices.traefik.containo.us</customResourceDefinition>
        <customResourceDefinition>tlsstores.traefik.containo.us</customResourceDefinition>
        <customResourceDefinition>tlsoptions.traefik.containo.us</customResourceDefinition>
        <customResourceDefinition>middlewares.traefik.containo.us</customResourceDefinition>
        <customResourceDefinition>ingressrouteudps.traefik.containo.us</customResourceDefinition>
        <customResourceDefinition>ingressroutetcps.traefik.containo.us</customResourceDefinition>
        <customResourceDefinitions>ingressroutes.traefik.containo.us</customResourceDefinitions>
    </customResourceDefinitions>
</resources>

Example IngressRoute definition:

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: ingressroutes.traefik.containo.us

spec:
  group: traefik.containo.us
  version: v1alpha1
  names:
    kind: IngressRoute
    plural: ingressroutes
    singular: ingressroute
  scope: Namespaced

But when running the k8s:resource I get the error:

Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.0.2:resource (default-cli) on project demo:
Execution default-cli of goal org.eclipse.jkube:kubernetes-maven-plugin:1.0.2:resource failed: Unknown type
'ingressroute' for file 005-ingressroute.yml. Must be one of : pr, lr, pv, project, replicaset, cronjob, ds,
statefulset, clusterrolebinding, pvc, limitrange, imagestreamtag, replicationcontroller, is, rb, rc, ingress, route,
projectrequest, job, rolebinding, rq, template, serviceaccount, bc, rs, rbr, role, pod, oauthclient, ns,
resourcequota, secret, persistemtvolumeclaim, istag, customerresourcedefinition, sa, persistentvolume, crb,
clusterrb, crd, deploymentconfig, configmap, deployment, imagestream, svc, rolebindingrestriction, cj, cm,
buildconfig, daemonset, cr, crole, pb, clusterrole, pd, policybinding, service, namespace, dc