티스토리 뷰

Cloud/Kubernetes

kubent(no trouble)

Jacob_baek 2023. 3. 14. 14:50

kubernetes는 다양한 API version을 제공하고 있고 Upgrade 시에 이로 인한 지원되지 않는다는 에러를 받게되는 경우가 종종 있다.
이를 좀더 쉽게 접근하기 위해 다양한 도구들이 제공되고 있다.

이중 kubet(No Trouble)에 대한 사용법을 간단히 정리하고자 한다.

먼저 help message는 다음과 같다.
help message에서 볼수 있듯이 manifest 파일 및 helm chart 그리고 cluster 자체에 대한 검사도 가능하다.

jacob@laptop:~ $ ./kubent -h
Usage of ./kubent:
  -A, --additional-annotation strings   additional annotations that should be checked to determine the last applied config
  -a, --additional-kind strings         additional kinds of resources to report in Kind.version.group.com format
  -c, --cluster                         enable Cluster collector (default true)
  -x, --context string                  kubeconfig context
  -e, --exit-error                      exit with non-zero code when issues are found
  -f, --filename strings                manifests to check, use - for stdin
      --helm3                           enable Helm v3 collector (default true)
  -k, --kubeconfig string               path to the kubeconfig file
  -l, --log-level string                set log level (trace, debug, info, warn, error, fatal, panic, disabled) (default "info")
  -o, --output string                   output format - [text|json|csv] (default "text")
  -O, --output-file string              output file, use - for stdout (default "-")
  -t, --target-version string           target K8s version in SemVer format (autodetected by default)
  -v, --version                         prints the version of kubent and exits
pflag: help requested

기본적으로는 cluster에 대한 검사가 default:true 인 상태이기에 진행하게 되면 아래와 같은 결과를 얻을 수 있다.

jacob@laptop:~ $ ./kubent -t 1.26.0
2:06PM INF >>> Kube No Trouble `kubent` <<<
2:06PM INF version nightly-0.7.0-23-g1d31e54 (git sha 1d31e547f59ad33022e25460ebd626f9c72266c2)
2:06PM INF Initializing collectors and retrieving data
2:06PM INF Target K8s version is 1.26.0
2:06PM INF Retrieved 59 resources from collector name=Cluster
2:06PM INF Retrieved 0 resources from collector name="Helm v3"
2:06PM INF Loaded ruleset name=custom.rego.tmpl
2:06PM INF Loaded ruleset name=deprecated-1-16.rego
2:06PM INF Loaded ruleset name=deprecated-1-22.rego
2:06PM INF Loaded ruleset name=deprecated-1-25.rego
2:06PM INF Loaded ruleset name=deprecated-1-26.rego
2:06PM INF Loaded ruleset name=deprecated-future.rego
__________________________________________________________________________________________
>>> Deprecated APIs removed in 1.25 <<<
------------------------------------------------------------------------------------------
KIND                  NAMESPACE     NAME                 API_VERSION      REPLACE_WITH (SINCE)
PodDisruptionBudget   kube-system   coredns-pdb          policy/v1beta1   policy/v1 (1.21.0)
PodDisruptionBudget   kube-system   konnectivity-agent   policy/v1beta1   policy/v1 (1.21.0)
PodDisruptionBudget   kube-system   metrics-server-pdb   policy/v1beta1   policy/v1 (1.21.0)

실제 동작은 아래와 같은 rego language 로 생성한 파일을 기반으로 policy 검사를 수행하고 여기에 위반(실제 위반이라기보다 deprecated된 api라 정의된 api가 사용되고 있는 경우)된 resource에 대해 출력을 하게 된다.

특정 파일에 특정 버전에 대한 검사를 해보고자 한다면 아래와 같이 파일과 버전을 명시해주면 된다.
아래는 1.16에서 deprecated된 extensions/v1beta1 이 선언된 파일을 kubent로 검사하는 예제이며 아래와 같이 변경되어야 하는 부분을 언급하고 있다.
(참고로 기본적으로 cluster / helm을 true로 동작되기에 이를 false로 해두면 실행시간이 절약된다.)

jacob@laptop:~ $ kubent -c=false --helm3=false -f psp.yaml -t 1.24.9
1:30PM INF >>> Kube No Trouble `kubent` <<<
1:30PM INF version nightly-0.7.0-23-g1d31e54 (git sha 1d31e547f59ad33022e25460ebd626f9c72266c2)
1:30PM INF Initializing collectors and retrieving data
1:30PM INF Target K8s version is 1.24.9
1:30PM INF Retrieved 2 resources from collector name=File
1:30PM INF Loaded ruleset name=custom.rego.tmpl
1:30PM INF Loaded ruleset name=deprecated-1-16.rego
1:30PM INF Loaded ruleset name=deprecated-1-22.rego
1:30PM INF Loaded ruleset name=deprecated-1-25.rego
1:30PM INF Loaded ruleset name=deprecated-1-26.rego
1:30PM INF Loaded ruleset name=deprecated-future.rego
__________________________________________________________________________________________
>>> Deprecated APIs removed in 1.16 <<<
------------------------------------------------------------------------------------------
KIND                NAMESPACE     NAME                  API_VERSION          REPLACE_WITH (SINCE)
PodSecurityPolicy   <undefined>   appsales-anyuid-psp   extensions/v1beta1   policy/v1beta1 (1.10.0)

이를 CICD Pipeline 상에 추가하여 사전에 앱 배포시 혹은 앱 배포 전에 확인할수 있도록 활용하기도 한다.

'Cloud > Kubernetes' 카테고리의 다른 글

trivy-operator  (0) 2023.04.01
Postee  (0) 2023.03.17
Vertical Pods Autoscaler  (0) 2023.02.16
Custom Container Registry with containerd runtime on Kubernetes  (0) 2023.02.13
cert-manager with ingress-nginx  (0) 2023.02.13
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함