crenshaw-dev
crenshaw-dev

Reputation: 8354

How can I make kubectl silent?

I'm trying to start port-forwarding in the background while suppressing all output. Here is what I've tried:

kubectl port-forward pod-name 1234:1234 > /dev/null 2>&1 &

Yet when I initiate connections, I still see messages like this:

Handling connection for 1234

As I understand it, both standard output and error should be directed to /dev/null.

My belief seems to be confirmed by the silence of this script:

echo "hi" > /dev/null 2>&1 &      # test stdout silence
>&2 echo "hi" > /dev/null 2>&1 &  # test stderr silence

(Note: I had to run these in a script rather than a shell, to avoid my shell's default output about subshells.)

I don't know what else I can do to suppress the kubectl port-forward output. What am I missing?

Upvotes: 13

Views: 11128

Answers (2)

sctx
sctx

Reputation: 168

From my experience it is possible to make kubectl silent by swapping 2>&1 with > /dev/null. Otherwise it won't work.

kubectl port-forward pod-name 1234:1234 > /dev/null 2>&1 &

Upvotes: 7

gokareless
gokareless

Reputation: 1253

Here is what worked in my case (after command execution output is completely silent):

kubectl port-forward pod-name 1234:1234 2>&1 >/dev/null &

which says send stderr output to the same place where stdout output which is /dev/null

Tested for:

Ubuntu 18.04

Kernel 5.4.0-70-generic

GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)

Upvotes: 10

Related Questions