Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make kubectl silent?

Tags:

bash

kubectl

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?

like image 592
crenshaw-dev Avatar asked Oct 15 '22 02:10

crenshaw-dev


1 Answers

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)

like image 184
gokareless Avatar answered Nov 15 '22 12:11

gokareless