Silence warnings in output from kubectl

11/2/2020

Is there a way to silence warning messages from kubectl, such as what is shown below for deprecation notices?

Warning: rbac.authorization.k8s.io/v1beta1 ClusterRoleBinding is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 ClusterRoleBinding
Warning: rbac.authorization.k8s.io/v1beta1 RoleBinding is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 RoleBinding
Warning: apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
Warning: admissionregistration.k8s.io/v1beta1 ValidatingWebhookConfiguration is deprecated in v1.16+, unavailable in v1.22+; use admissionregistration.k8s.io/v1 ValidatingWebhookConfiguration
Warning: admissionregistration.k8s.io/v1beta1 MutatingWebhookConfiguration is deprecated in v1.16+, unavailable in v1.22+; use admissionregistration.k8s.io/v1 MutatingWebhookConfiguration

It appears these warnings are occurring with Kubernetes 1.19.

-- dhelfand
kubectl
kubernetes

2 Answers

8/9/2021

For anyone who would like more details on this subject, there is a blog post from Kubernetes that goes into much more detail on this subject.

The answer is that kubectl does not itself provide a way to silence these warnings. In general, kubectl will show these deprecation warnings for versions 1.19 and beyond.

client-go offers a way for developers of Kubernetes CLIs to handle these warnings in particular ways, but kubectl has chosen to always show these warnings.

In general, unless these warnings are causing an issue for existing processes, it is probably better to show these warnings. If there is some issue (e.g. logs are cluttered with these warnings), it is probably useful to come up with some custom scripting like mentioned by @acid_fuji.

-- dhelfand
Source: StackOverflow

11/3/2020

To add on top of the previous answer you may also want to redirect stderr output into null device. Its not ideal though since it will dispose all the stderr, not only warnings.

kubectl get pod 2> /dev/null

null device is an device file that discards all written data. The null device is typically used for disposing of unwanted output streams of a process, or as a convenient empty file for input streams.

The best here would be to redirect stderr into stdout and then filter it with grep.

kubectl get pod 2>&1 | grep -i -v "Warn" | grep -i -v "Deprecat" 
-- acid_fuji
Source: StackOverflow