0

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
msteff
  • 1
  • 2
  • Hello, Which version of Eclipse JKube are you using? – Rohan Kumar Feb 09 '21 at 06:27
  • Using version 1.0.2. – msteff Feb 10 '21 at 11:44
  • I have provided an answer with recently released version v1.1.0. Could you please review and provide feedback if it's working for you? – Rohan Kumar Feb 10 '21 at 11:46
  • If possible, Could you please provide a reproducer project which I can try out? If not, I can provide a project with your provided `IngressRoute` fragment which you can check to see what's missing in your configuration. – Rohan Kumar Feb 10 '21 at 11:49
  • Sure. https://bitbucket.org/emercos/demo/src/master/ – msteff Feb 11 '21 at 15:27
  • I was able to get it working with these changes: `mv src/main/jkube/005-ingressroute.yml src/main/jkube/005-ingressroute-cr.yml` `mv src/main/jkube/002-tlsoption.yml src/main/jkube/002-tlsoption-cr.yml` – Rohan Kumar Feb 11 '21 at 15:49
  • In case you still face problems, please reach out to us on our gitter channel: https://gitter.im/eclipse/jkube – Rohan Kumar Feb 11 '21 at 15:51
  • It works all now! I can maven-build, push to docker, and deploy in my kubernetes baremetal cloud on Hetzner. Cool - thanks a lot Rohan. I would not have figured that solution out on my own. – msteff Feb 13 '21 at 07:25
  • Hi Rohan - were you able to re-apply without undeploy first ? It works fine if I re-apply using kubectl manually, but when running the k8s:apply target twice I get:
    ..Failure executing: PUT at: https://168.119.233.19:6443/apis/traefik.containo.us/v1alpha1/namespaces/default/tlsoptions/quasifacttlsoption. Message: tlsoptions.traefik.containo.us "quasifacttlsoption" is invalid: metadata.resourceVersion: Invalid value: 0x0: must be specified for an update...
    
    – msteff Feb 13 '21 at 09:51
  • oh, yeah. I was facing this too. Could you please create an issue on our Github repository? – Rohan Kumar Feb 15 '21 at 15:59
  • https://github.com/eclipse/jkube/issues/577 Thanks. – msteff Feb 16 '21 at 16:22
  • Thanks a lot. It will be fixed in our upcoming release(v1.2.0). – Rohan Kumar Feb 16 '21 at 16:53
  • Hello, We have released v1.2.0. Would appreciate if you could try it out and provide feedback whenever you get time. – Rohan Kumar Apr 03 '21 at 16:46
  • Hi Rohan - sorry for the delay. Yes, it works fine with 1.2.0. I can re-apply without undeploy first. – msteff Apr 11 '21 at 19:51
  • Thanks a lot for trying it out. Shall we close https://github.com/eclipse/jkube/issues/577 ? – Rohan Kumar Apr 12 '21 at 06:14
  • Yes, problem solved. Thank you for your help! – msteff Apr 13 '21 at 07:02

2 Answers2

0

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

Rohan Kumar
  • 5,427
  • 8
  • 25
  • 40
0

@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
msteff
  • 1
  • 2