Kubernetes 객체 분석 및 안정성과 보안 향상을 위한 권장 사항을 제공합니다. kube-score는 Kubernetes YAML 및 Charts에서 다운타임과 버그를 사전에 방지합니다. Kubernetes를 위한 정적 코드 분석 도구입니다.
kube-score는 설치가 간편하며 다음 소스에서 제공됩니다.
| 배포 방식 | 명령어 / 링크 |
|---|---|
| macOS, Linux, Windows용 사전 빌드된 바이너리 | GitHub releases |
| Docker | docker pull zegl/kube-score (Docker Hub) |
| Homebrew (macOS 및 Linux) | brew install kube-score |
| Krew (macOS 및 Linux) | kubectl krew install score |
전체 검사 항목 목록은 README_CHECKS.md를 참조하세요.
NetworkPolicy의 대상이어야 하며, egress 및 ingress 규칙이 모두 권장됨PodDisruptionPolicy가 있어야 함
kube-score는 CI/CD 환경에서 실행할 수 있으며, 치명적인 오류가 발견되면 종료 코드 1로 종료됩니다.
--exit-one-on-warning 인수를 사용하여 트리거 수준을 경고로 변경할 수 있습니다.
kube-score의 입력은 최상의 결과를 위해 동일한 네임스페이스에 배포하는 모든 애플리케이션이어야 합니다.
helm template my-app | kube-score score -
kustomize build . | kube-score score -
kube-score score my-app/*.yaml
kube-score score my-app/deployment.yaml my-app/service.yaml
kubectl api-resources --verbs=list --namespaced -o name \
| xargs -n1 -I{} bash -c "kubectl get {} --all-namespaces -oyaml && echo ---" \
| kube-score score -
docker run -v $(pwd):/project zegl/kube-score:latest score my-app/*.yaml
Usage of kube-score:
kube-score [action] --flags
Actions:
score Checks all files in the input, and gives them a score and recommendations
list Prints a CSV list of all available score checks
version Print the version of kube-score
help Print this message
Flags for score:
--disable-ignore-checks-annotations Set to true to disable the effect of the 'kube-score/ignore' annotations
--disable-optional-checks-annotations Set to true to disable the effect of the 'kube-score/enable' annotations
--enable-optional-test strings Enable an optional test, can be set multiple times
--exit-one-on-warning Exit with code 1 in case of warnings
--help Print help
--ignore-container-cpu-limit Disables the requirement of setting a container CPU limit
--ignore-container-memory-limit Disables the requirement of setting a container memory limit
--ignore-test strings Disable a test, can be set multiple times
--kubernetes-version string Setting the kubernetes-version will affect the checks ran against the manifests. Set this to the version of Kubernetes that you're using in production for the best results. (default "v1.18")
-o, --output-format string Set to 'human', 'json', 'ci' or 'sarif'. If set to ci, kube-score will output the program in a format that is easier to parse by other programs. Sarif output allows for easier integration with CI platforms. (default "human")
--output-version string Changes the version of the --output-format. The 'json' format has version 'v2' (default) and 'v1' (deprecated, will be removed in v1.7.0). The 'human' and 'ci' formats has only version 'v1' (default). If not explicitly set, the default version for that particular output format will be used.
-v, --verbose count Enable verbose output, can be set multiple times for increased verbosity.
검사는 --ignore-test 플래그를 사용하여 프로그램 전체 실행에서 무시할 수 있습니다.
또한 오브젝트에 kube-score/ignore 어노테이션을 추가하여 오브젝트별로 검사를 무시할 수도 있습니다.
값은 테스트 ID의 쉼표로 구분된 문자열이어야 합니다.
예시:
이 오브젝트를 테스트하면 NodePort 유형의 서비스 사용에 대해 경고하는 service-type 테스트가 일시적으로 비활성화됩니다.
apiVersion: v1
kind: Service
metadata:
name: node-port-service-with-ignore
namespace: foospace
annotations:
kube-score/ignore: service-type
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: NodePort
선택적 검사는 --enable-optional-test 플래그를 사용하여 프로그램 전체 실행에서 활성화할 수 있습니다.
또한 오브젝트에 kube-score/enable 어노테이션을 추가하여 오브젝트별로 검사를 활성화할 수도 있습니다.
값은 테스트 ID의 쉼표로 구분된 문자열이어야 합니다.
예시:
이 오브젝트를 테스트하면 container-seccomp-profile 검사가 활성화됩니다.
또한 kube-score/ignore에 정의된 여러 검사도 동시에 무시됩니다.
apiVersion: apps/v1
kind: Deployment
metadata:
name: optional-test-manifest-deployment
labels:
app: optional-test-manifest
annotations:
kube-score/ignore: pod-networkpolicy,container-resources,container-image-pull-policy,container-security-context-privileged,container-security-context-user-group-id,container-security-context-readonlyrootfilesystem,container-ephemeral-storage-request-and-limit
kube-score/enable: container-seccomp-profile
spec:
replicas: 1
selector:
matchLabels:
app: optional-test-manifest
template:
metadata:
labels:
app: optional-test-manifest
spec:
containers:
- name: optional-test-manifest
image: busybox:1.34
command:
- /bin/sh
- -c
- date; env; tail -f /dev/null
kube-score를 빌드하려면 Go 1.21 이상이 필요합니다. 이 저장소를 클론한 후 다음을 실행하세요:
# 프로젝트 빌드
go build ./cmd/kube-score
# 모든 테스트 실행
go test -v ./...
도움을 주고 싶으신가요? 자세한 내용은 기여 지침을 확인하세요. 🤩
| 프로젝트 | 버전 |
|---|---|
| go.dev | ^1.21 |