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 10 years ago
  • Reactions: 19
  • Comments: 53 (32 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)

3 is the only case left that requires work or a decision to be made about whether it is a valid use case.

The real decision is about whether to make --quiet the default.

There is a third decision about whether to output the extra status info as stdout vs stderr. For reference, in docker, the equivalent pulling image text goes to stdout, not stderr. This might split the difference on the --quiet as default decision.

# kubectl version
Client Version: version.Info{Major:"1", Minor:"5+", GitVersion:"v1.5.0-alpha.1.973+5a0c22e09ab769-dirty", GitCommit:"5a0c22e09ab7695727b9c1be062f39e346960e9f", GitTreeState:"dirty", BuildDate:"2016-10-26T17:36:07Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"5+", GitVersion:"v1.5.0-alpha.1.973+5a0c22e09ab769-dirty", GitCommit:"5a0c22e09ab7695727b9c1be062f39e346960e9f", GitTreeState:"dirty", BuildDate:"2016-10-27T00:38:12Z", GoVersion:"go1.7.1", Compiler:"gc", Platform:"linux/amd64"}

1. fixed by #31558, correct behavior with --quiet

root@masterbuilder:~/go/src/k8s.io/kubernetes# kubectl run test --rm --restart=Never -it --image=ubuntu -- date
Waiting for pod default/test to be running, status is Pending, pod ready: false
Thu Oct 27 00:58:05 UTC 2016
pod "test" deleted
root@masterbuilder:~/go/src/k8s.io/kubernetes# kubectl run test --rm --restart=Never -it --image=ubuntu --quiet -- date
Thu Oct 27 00:58:15 UTC 2016

2. correct behavior with --quiet

root@masterbuilder:~/go/src/k8s.io/kubernetes# 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
If you don't see a command prompt, try pressing enter.
                                                      Thu Oct 27 01:06:20 UTC 2016
Waiting for pod default/test to terminate, status is Running
pod "test" deleted
root@masterbuilder:~/go/src/k8s.io/kubernetes# kubectl run test --rm --restart=Never -it --image=ubuntu --quiet -- bash -c "sleep 3; date; sleep 3"
Thu Oct 27 01:06:32 UTC 2016

3. no change due to differing definition of flags from docker. I am not sure this is a valid use case for k8s. 4. correct behavior with --quiet

root@masterbuilder:~/go/src/k8s.io/kubernetes# kubectl run test --rm --restart=Never -i --image=ubuntu -- date
Waiting for pod default/test to be running, status is Pending, pod ready: false
Thu Oct 27 01:09:15 UTC 2016
pod "test" deleted
root@masterbuilder:~/go/src/k8s.io/kubernetes# kubectl run test --rm --restart=Never -i --image=ubuntu --quiet -- date
Thu Oct 27 01:09:24 UTC 2016

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 .