
Analisi degli oggetti Kubernetes con raccomandazioni per migliorare affidabilità e sicurezza. kube-score previene attivamente tempi di inattività e bug nei tuoi YAML e Charts Kubernetes. Analisi statica del codice per Kubernetes.

kube-score è uno strumento che esegue l'analisi statica del codice delle definizioni degli oggetti Kubernetes.
L'output è un elenco di raccomandazioni su cosa puoi migliorare per rendere la tua applicazione più sicura e resiliente.
Puoi provare kube-score nel browser con la demo online (sorgente).
kube-score è facile da installare ed è disponibile dalle seguenti fonti:
Per un elenco completo dei controlli, vedi README_CHECKS.md.
NetworkPolicy, si raccomandano regole sia di egress che di ingressPodDisruptionPolicy
kube-score può essere eseguito nel tuo ambiente CI/CD e terminerà con codice di uscita 1 se viene trovato un errore critico. Il livello di trigger può essere cambiato a warning con l'argomento --exit-one-on-warning.
L'input a kube-score dovrebbero essere tutte le applicazioni che distribuisci nello stesso namespace per il miglior risultato.
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.
I test possono essere ignorati nell'intera esecuzione del programma, con il flag --ignore-test.
Un test può anche essere ignorato per oggetto, aggiungendo l'annotazione kube-score/ignore all'oggetto. Il valore dovrebbe essere una stringa separata da virgole dei ID test.
Esempio:
Testare questo oggetto disabiliterà temporaneamente il test service-type, che avvisa contro l'uso di servizi di 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
I test opzionali possono essere abilitati nell'intera esecuzione del programma, con il flag --enable-optional-test.
Un test può anche essere abilitato per oggetto, aggiungendo l'annotazione kube-score/enable all'oggetto. Il valore dovrebbe essere una stringa separata da virgole dei ID test.
Esempio:
Testare questo oggetto abiliterà il test container-seccomp-profile. Inoltre, anche più test definiti da kube-score/ignore vengono ignorati contemporaneamente.
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 richiede Go 1.21 o successivo per essere compilato. Clona questo repository, e poi:
# Build the project
go build ./cmd/kube-score
# Run all tests
go test -v ./...
Vuoi dare una mano? Dai un'occhiata alle Linee guida per contribuire per maggiori informazioni. 🤩
| Progetto | Versione |
|---|---|
| go.dev | ^1.21 |
| Distribuzione | Comando / Link |
|---|
| Binari precompilati per 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 |