<p>I was trying to use io.fabric8 api to create a few resources in kubernetes using a pod-spec.yaml.</p>

<pre><code>Config config = new ConfigBuilder()
                  .withNamespace("ag")
                  .withMasterUrl(K8_URL)
                  .build();
try (final KubernetesClient client = new DefaultKubernetesClient(config)) {

            LOGGER.info("Master: " + client.getMasterUrl());

            LOGGER.info("Loading File : " + args[0]);
            Pod pod = client.pods().load(new FileInputStream(args[0])).get();
            LOGGER.info("Pod created with name : " + pod.toString());

} catch (Exception e) {

            LOGGER.error(e.getMessage(), e);

}
</code></pre>

<p>The above code works if the resource type is of POD. Similarly for other resource type it is working fine.
But if the yaml has multiple resource type like POD and service in the same file, how to use fabric8 Api ? </p>

<p>I was trying to use <code>client.load(new FileInputStream(args[0])).createOrReplace();</code> but it is crashing with the below exception:</p>

<pre><code>java.lang.NullPointerException
    at java.net.URI$Parser.parse(URI.java:3042)
    at java.net.URI.&lt;init&gt;(URI.java:588)
    at io.fabric8.kubernetes.client.utils.URLUtils.join(URLUtils.java:48)
    at io.fabric8.kubernetes.client.dsl.base.BaseOperation.getMandatory(BaseOperation.java:208)
    at io.fabric8.kubernetes.client.dsl.base.BaseOperation.get(BaseOperation.java:177)
    at io.fabric8.kubernetes.client.handlers.PodHandler.reload(PodHandler.java:53)
    at io.fabric8.kubernetes.client.handlers.PodHandler.reload(PodHandler.java:32)
    at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.createOrReplace(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:202)
    at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.createOrReplace(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:62)
    at com.nokia.k8s.InterpreterLanuch.main(InterpreterLanuch.java:66)
</code></pre>

<p>Yaml file used</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  generateName: zep-ag-pod
  annotations:
    kubernetes.io/psp: restricted
    spark-app-name: Zeppelin-spark-shared-process
  namespace: ag
  labels:
    app: zeppelin
    int-app-selector: shell-123

spec:
  containers:
    - name: ag-csf-zep
      image: bcmt-registry:5000/zep-spark2.2:9
      imagePullPolicy: IfNotPresent
      command: ["/bin/bash"]
      args: ["-c","echo Hi &amp;&amp; sleep 60 &amp;&amp; echo Done"]
      securityContext:
        allowPrivilegeEscalation: false
        capabilities:
          drop:
          - ALL
        runAsNonRoot: true
  securityContext:
    fsGroup: 2000
    runAsUser: 1510
  serviceAccount: csfzeppelin
  serviceAccountName: csfzeppelin
---
apiVersion: v1
kind: Service
metadata:
  name: zeppelin-service
  namespace: ag
  labels:
    app: zeppelin
spec:
  type: NodePort
  ports:
  - name: zeppelin-service
    port: 30099
    protocol: TCP
    targetPort: 8080
  selector:
    app: zeppelin
</code></pre>

Ajay
<p>You don't need to specify resource type whenever loading a file with multiple documents. You simply need to do:</p>

<pre><code>  // Load Yaml into Kubernetes resources
  List&lt;HasMetadata&gt; result = client.load(new FileInputStream(args[0])).get();
  // Apply Kubernetes Resources
  client.resourceList(result).inNamespace(namespace).createOrReplace() 
</code></pre>
