
Análisis de objetos Kubernetes con recomendaciones para mejorar la fiabilidad y la seguridad. kube-score previene activamente el tiempo de inactividad y los errores en tus YAML y Charts de Kubernetes. Análisis estático de código para Kubernetes.

kube-score es una herramienta que realiza análisis estático de código de sus definiciones de objetos de Kubernetes.
La salida es una lista de recomendaciones sobre lo que puede mejorar para hacer su aplicación más segura y resistente.
Puede probar kube-score en el navegador con la demo en línea (código fuente).
kube-score es fácil de instalar y está disponible desde las siguientes fuentes:
Para una lista completa de verificaciones, consulte README_CHECKS.md.
NetworkPolicy, se recomiendan reglas de salida y entradaPodDisruptionPolicy
kube-score puede ejecutarse en su entorno CI/CD y saldrá con código de salida 1 si se ha encontrado un error crítico. El nivel de disparo se puede cambiar a advertencia con el argumento --exit-one-on-warning.
La entrada a kube-score debe ser todas las aplicaciones que implemente en el mismo namespace para obtener el mejor 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.
Las pruebas se pueden ignorar en toda la ejecución del programa, con la bandera --ignore-test.
Una prueba también se puede ignorar por objeto, agregando la anotación kube-score/ignore al objeto. El valor debe ser una cadena separada por comas de los IDs de prueba.
Ejemplo:
Probar este objeto deshabilitará temporalmente la prueba service-type, que advierte contra el uso de servicios de 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
Las pruebas opcionales se pueden habilitar en toda la ejecución del programa, con la bandera --enable-optional-test.
Una prueba también se puede habilitar por objeto, agregando la anotación kube-score/enable al objeto. El valor debe ser una cadena separada por comas de los IDs de prueba.
Ejemplo:
Probar este objeto habilitará la prueba container-seccomp-profile. Además, múltiples pruebas definidas por kube-score/ignore también se ignoran al mismo tiempo.
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 requiere Go 1.21 o posterior para compilar. Clone este repositorio y luego:
# Build the project
go build ./cmd/kube-score
# Run all tests
go test -v ./...
¿Quiere ayudar? Eche un vistazo a las Guías de Contribución para más información. 🤩
| Proyecto | Versión |
|---|---|
| go.dev | ^1.21 |
| Distribución | Comando / Enlace |
|---|
| Binarios precompilados para macOS, Linux y Windows | GitHub releases |
| Docker | docker pull zegl/kube-score (Docker Hub) |
| Homebrew (macOS y Linux) | brew install kube-score |
| Krew (macOS y Linux) | kubectl krew install score |