<p>I have a problem with fabric8io <a href="https://github.com/fabric8io/kubernetes-client" rel="nofollow noreferrer">kubernetes-client</a> using.</p>
<p>What i want: Creating Kafka cluster with Strimzi operator in Kubernetes.
If i do all steps from <a href="https://strimzi.io/docs/operators/latest/quickstart.html" rel="nofollow noreferrer">Strimzi quickstart guide</a> with CLI and kubectl it's all good.</p>
<p>But when i load yaml resources with <code>kubernetes-client:5.2.1</code> library from Java code, there is an Exception occurs:</p>
<pre class="lang-java prettyprint-override"><code>io.fabric8.kubernetes.client.KubernetesClientException: An error has occurred.
  at io.fabric8.kubernetes.client.KubernetesClientException.launderThrowable(KubernetesClientException.java:64)
  at io.fabric8.kubernetes.client.KubernetesClientException.launderThrowable(KubernetesClientException.java:53)
  at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:140)
  at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:101)
  at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.&lt;init&gt;(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:272)
  at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.&lt;init&gt;(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:252)
  at io.fabric8.kubernetes.client.DefaultKubernetesClient$1.&lt;init&gt;(DefaultKubernetesClient.java:175)
  at io.fabric8.kubernetes.client.DefaultKubernetesClient.load(DefaultKubernetesClient.java:175)
  at app.test.main(test.java:38)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: No resource type found for:kafka.strimzi.io/v1#Kafka
 at [Source: (String)&quot;{&quot;apiVersion&quot;:&quot;kafka.strimzi.io/v1&quot;,&quot;kind&quot;:&quot;Kafka&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;my-cluster&quot;},&quot;spec&quot;:{&quot;kafka&quot;:{&quot;replicas&quot;:1,&quot;listeners&quot;:[{&quot;name&quot;:&quot;plain&quot;,&quot;port&quot;:9092,&quot;type&quot;:&quot;internal&quot;,&quot;tls&quot;:false},{&quot;name&quot;:&quot;tls&quot;,&quot;port&quot;:9093,&quot;type&quot;:&quot;internal&quot;,&quot;tls&quot;:true,&quot;authentication&quot;:{&quot;type&quot;:&quot;tls&quot;}},{&quot;name&quot;:&quot;external&quot;,&quot;port&quot;:9094,&quot;type&quot;:&quot;nodeport&quot;,&quot;tls&quot;:false}],&quot;storage&quot;:{&quot;type&quot;:&quot;jbod&quot;,&quot;volumes&quot;:[{&quot;id&quot;:0,&quot;type&quot;:&quot;persistent-claim&quot;,&quot;size&quot;:&quot;1Gi&quot;,&quot;deleteClaim&quot;:false}]},&quot;config&quot;:{&quot;offsets.topic.replication.factor&quot;:1,&quot;transacti&quot;[truncated 226 chars]; line: 1, column: 726]
</code></pre>
<p>Problem occurs when i load this file: <a href="https://github.com/strimzi/strimzi-kafka-operator/blob/master/examples/kafka/kafka-ephemeral.yaml" rel="nofollow noreferrer">yaml config</a>.</p>
<p>I load resource like:</p>
<pre class="lang-java prettyprint-override"><code> KubernetesClient client = new DefaultKubernetesClient();
InputStream is = ...;
client.load(is).inNamespace(&quot;my_namespace&quot;).createOrReplace();
</code></pre>
<p>Please help me!</p>
<p>P.S: And sorry for my English.</p>

<p>I'm from Fabric8 team. <code>Kafka</code> is a Custom Resource which means it's model is not registered in KubernetesClient so this is the reason why you're facing <code>No resource type found for:kafka.strimzi.io/v1#Kafka</code> error from KubenetesClient. KubernetesClient provides two methods for dealing with Custom Resources:</p>
<ol>
<li>Typeless API - Usage of CustomResources as raw Hashmaps</li>
<li>Typed API    - Provide POJOs for CustomResource types</li>
</ol>
<p>I'll provide examples of using both APIs to load your Kafka yaml fragment.</p>
<p><strong>Typeless API:</strong></p>
<p>For Typeless API you would need to provide a <code>CustomResourceDefinitionContext</code>, an object with details of CustomResource group, version, kind, plural etc. Here is how it would look like:
<a href="https://github.com/rohanKanojia/stackoverflow-code/blob/master/java-posts/src/main/java/in/rohaan/KafkaLoadTypeles.java" rel="nofollow noreferrer">KafkaLoadTypeless.java</a></p>
<pre class="lang-java prettyprint-override"><code>try (KubernetesClient client = new DefaultKubernetesClient()) {
    CustomResourceDefinitionContext context = new CustomResourceDefinitionContext.Builder()
            .withScope(&quot;Namespaced&quot;)
            .withVersion(&quot;v1beta2&quot;)
            .withGroup(&quot;kafka.strimzi.io&quot;)
            .withPlural(&quot;kafkas&quot;)
            .build();

    InputStream is = KafkaLoadTypeles.class.getResourceAsStream(&quot;/test-kafka.yml&quot;);

    Map&lt;String, Object&gt; createdKafka = client.customResource(context).inNamespace(&quot;default&quot;).createOrReplace(is);
} catch (IOException ioException) {
    ioException.printStackTrace();
}
</code></pre>
<p><strong>Typed API:</strong></p>
<p>For typed API, you would need to provide types for <code>Kafka</code> resource. You can find these types in Strimzi API dependency. I had to add this dependency in my project in order to use <code>Kafka</code> classes:</p>
<pre class="lang-xml prettyprint-override"><code>        &lt;dependency&gt;
            &lt;groupId&gt;io.strimzi&lt;/groupId&gt;
            &lt;artifactId&gt;api&lt;/artifactId&gt;
            &lt;version&gt;0.22.0&lt;/version&gt;
            &lt;exclusions&gt;
                &lt;exclusion&gt;
                    &lt;groupId&gt;io.fabric8&lt;/groupId&gt;
                    &lt;artifactId&gt;kubernetes-client&lt;/artifactId&gt;
                &lt;/exclusion&gt;
            &lt;/exclusions&gt;
        &lt;/dependency&gt;
</code></pre>
<p>After adding this, I was able to use Typed API like this:
<a href="https://github.com/rohanKanojia/stackoverflow-code/blob/master/java-posts/src/main/java/in/rohaan/KafkaLoadTyped.java" rel="nofollow noreferrer">KafkaLoadTyped.java</a></p>
<pre class="lang-java prettyprint-override"><code>try (KubernetesClient client = new DefaultKubernetesClient()) {
    MixedOperation&lt;Kafka, KafkaList, Resource&lt;Kafka&gt;&gt; kafkaClient = client.customResources(Kafka.class, KafkaList.class);

    InputStream is = KafkaLoadTyped.class.getResourceAsStream(&quot;/test-kafka.yml&quot;);
    Kafka myClusterkafka = kafkaClient.load(is).get();
    kafkaClient.inNamespace(&quot;default&quot;).createOrReplace(myClusterkafka);
}
</code></pre>
