Home > database >  How to launch a pod and feed its input stream
How to launch a pod and feed its input stream

Time:11-30

I'm newbie to Kubernetes. I wonder how to launch a container programmatically in Java (or Scala), and feed the input stream of the process with some binary data. Probably I need a job. I've found how to launch a job, but I have no control over its input stream.

I can use any convenient Kubernetes client library.

I need it to launch a kaniko container and feed its input stream with a .tar.gz file generated on the fly (via the --context tar://stdin option).

I could do an exec over an existing kaniko container, but don't know to launch the container appropriately for this purpose, because the container doesn't include any shell.

CodePudding user response:

You can use kubectl run to create a pod and connect its stdin with option -i. Your container should termiate gracefully when the work is done.

Example:

echo "echo foo" | kubectl run -i busybox --image=busybox --restart=Never 

Reference:

https://jamesdefabia.github.io/docs/user-guide/kubectl/kubectl_run/

CodePudding user response:

Programmatically with the fabric8 Java client library, it can be done in this way:

https://github.com/fabric8io/kubernetes-client/blob/master/doc/CHEATSHEET.md#running-a-pod

try (KubernetesClient client = new KubernetesClientBuilder().build()) {
    client.run().inNamespace("default")
            .withName("kaniko")
            .withImage("gcr.io/kaniko-project/executor:latest")
            .done();
}

It is quite handy to set env. variables or add arguments.

Now I have to research, how to feed the standard input.

  • Related