Piping a file to stdin in Kubernetes Job

10/28/2019

Here we have a sample of the job

apiVersion: batch/v1
kind: Job
metadata:
  # Unique key of the Job instance
  name: example-job
spec:
  template:
    metadata:
      name: example-job
    spec:
      containers:
      - name: pi
        image: perl
        command: ["perl"]
        args: ["-Mbignum=bpi", "-wle", "print bpi(2000)"]
      # Do not restart containers after they exit
      restartPolicy: Never

I want to run a MySQL script as a command: mysql -hlocalhost -u1234 -p1234 --database=customer < script.sql

But Kubernetes documentation is silent about piping a file to stdin. How can I specify that in Kubernetes job config?

-- user2302485
bash
kubernetes
mysql

1 Answer

10/28/2019

Would set your command to something like [bash, -c, "mysql -hlocalhost -u1234 -p1234 --database=customer < script.sql"], since input redirection like that is actually a feature of your shell.

-- coderanger
Source: StackOverflow