kubernetes: `kubectl run` doesn’t work for simple "run command, parse result"

(source: user feedback)

First, it outputs Waiting for pod ... which gets mingled with commands output. Second, simple output often gets lost.

1. -it, date: doesn’t work

$ kubectl run test --rm --restart=Never -it --image=ubuntu -- date
Waiting for pod default/test to be running, status is Pending, pod ready: false
Error from server: Unrecognized input header

2. -it, bash sleep, then date: works with output mingled with command output

$ kubectl run test --rm --restart=Never -it --image=ubuntu -- bash -c "sleep 3; date; sleep 3"
Waiting for pod default/test to be running, status is Pending, pod ready: false

Hit enter for command prompt
                            Fri Jul  8 17:19:50 UTC 2016
pod "test" deleted

3. -t, bash sleep, then date: doesn’t work

$ kubectl run test --rm --restart=Never -t --image=ubuntu -- bash -c "sleep 3; date; sleep 3"
error: -i/--stdin is required for containers with -t/--tty=true
See 'kubectl run -h' for help and examples.

4. -i, date: works but output is still mingled

$ kubectl run test --rm --restart=Never -i --image=ubuntu -- date
Waiting for pod default/test to be running, status is Pending, pod ready: false
Fri Jul  8 17:21:59 UTC 2016
pod "test" deleted

Compared to docker run, all 4 cases return the same simple output:

$ docker run -i ubuntu date
Fri Jul  8 17:23:45 UTC 2016

@kubernetes/kubectl

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 19
  • Comments: 53 (36 by maintainers)

Commits related to this issue

Most upvoted comments

Still an issue in late 2020.

Has case 2 ever been fixed? Because I’m running into this now…

1 & 4 work as specified now.

2 still has the Hit enter for command prompt message and some weird spaces, but the only thing on stdout is the appropriate output. I’d be inclined to get rid of the message about the prompt.

3 is the only weird behavior where it’s just different than docker.

Yes, docker logs is stdout/err of the container.

This is what we used to have:

  1. start container
  2. time passes (or not)
  3. docker attach, logs=true (show logs, then attach)

This is what we have now:

  1. start container
  2. time passes (or not)
  3. docker attach, logs=false (don’t show logs, just attach and only show stdout/stderr emitted after attaching)

I like the idea of --quiet being implied with -i -t.

I also like the idea of an umbrella flag that covers it all. --interactive is the long-form of -i, though, isn’t it? How about --attached or –one-shot? Maybe --interactive is better.

Is there a use for -i that isn’t this? Maybe just -i -t together implies everything?

On Mon, Jul 11, 2016 at 5:14 PM, Janet Kuo notifications@github.com wrote:

Adding --quiet in #28801 https://github.com/kubernetes/kubernetes/pull/28801.

Some more thoughts from in-person discussion with @bgrant0607 https://github.com/bgrant0607 :

  1. We can default the --quiet mode when -it are both specified, or
  2. Add a flag (e.g. --interactive) that’d be equivalent to --restart=Never –quiet --rm (depending on what default makes sense for the users)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kubernetes/kubernetes/issues/28695#issuecomment-231902836, or mute the thread https://github.com/notifications/unsubscribe/AFVgVCuzAt0MXB_TfyoyndmPgOedf66Iks5qUtxcgaJpZM4JIOwB .