
Análise de objetos Kubernetes com recomendações para melhor confiabilidade e segurança. O kube-score previne ativamente tempo de inatividade e bugs em seus YAML e Charts do Kubernetes. Análise estática de código para Kubernetes.

kube-score é uma ferramenta que realiza análise estática de código das definições de seus objetos Kubernetes.
A saída é uma lista de recomendações do que você pode melhorar para tornar sua aplicação mais segura e resiliente.
Você pode testar o kube-score no navegador com a demonstração online (fonte).
O kube-score é fácil de instalar e está disponível nas seguintes fontes:
Para uma lista completa de verificações, veja README_CHECKS.md.
NetworkPolicy, recomenda-se regras de egress e ingressPodDisruptionPolicy
kube-score pode ser executado em seu ambiente CI/CD e sairá com código de saída 1 se um erro crítico for encontrado. O nível de disparo pode ser alterado para aviso com o argumento --exit-one-on-warning.
A entrada para kube-score deve ser todas as aplicações que você implanta no mesmo namespace para obter o melhor resultado.
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.
Os testes podem ser ignorados em toda a execução do programa, com a flag --ignore-test.
Um teste também pode ser ignorado por objeto, adicionando a anotação kube-score/ignore ao objeto. O valor deve ser uma string separada por vírgulas das IDs de teste.
Exemplo:
Testar este objeto desabilitará temporariamente o teste service-type, que alerta contra o uso de serviços do tipo NodePort.
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
Testes opcionais podem ser habilitados em toda a execução do programa, com a flag --enable-optional-test.
Um teste também pode ser habilitado por objeto, adicionando a anotação kube-score/enable ao objeto. O valor deve ser uma string separada por vírgulas das IDs de teste.
Exemplo:
Testar este objeto habilitará o teste container-seccomp-profile. Além disso, vários testes definidos por kube-score/ignore também são ignorados ao mesmo tempo.
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 requer Go 1.21 ou posterior para compilar. Clone este repositório e, em seguida:
# Build the project
go build ./cmd/kube-score
# Run all tests
go test -v ./...
Você quer ajudar? Dê uma olhada nas Diretrizes de Contribuição para mais informações. 🤩
| Projeto | Versão |
|---|---|
| go.dev | ^1.21 |
| Distribuição | Comando / Link |
|---|
| Pré-compilados para macOS, Linux e Windows | GitHub releases |
| Docker | docker pull zegl/kube-score (Docker Hub) |
| Homebrew (macOS e Linux) | brew install kube-score |
| Krew (macOS e Linux) | kubectl krew install score |