AI prompts
base on Easily check your clusters for use of deprecated APIs ![Kubent (Kube-No-Trouble) logo](./docs/imgs/kubent-logo.svg)
__*Easily check your clusters for use of deprecated APIs*__
Kubernetes 1.16 is slowly starting to roll out, not only across various managed
Kubernetes offerings, and with that come a lot of API deprecations[1][1].
*Kube No Trouble (__`kubent`__)* is a simple tool to check whether you're using
any of these API versions in your cluster and therefore should upgrade your
workloads first, before upgrading your Kubernetes cluster.
This tool will be able to detect deprecated APIs depending on how you deploy
your resources, as we need the original manifest to be stored somewhere. In
particular following tools are supported:
- **file** - local manifests in YAML or JSON
- **kubectl** - uses the `kubectl.kubernetes.io/last-applied-configuration` annotation
- **Helm v3** - uses Helm manifests stored as Secrets or ConfigMaps directly in individual namespaces
[1]: https://kubernetes.io/blog/2019/07/18/api-deprecations-in-1-16/
**Additional resources:**
- Blog post on K8s deprecated APIs and introduction of kubent: [Kubernetes: Deprecated APIs aka Introducing Kube-No-Trouble][2]
[2]: https://stepan.wtf/kubernetes-deprecated-apis-introducing-kubent/
## Install
Run the following command in your terminal to install `kubent` using a shell script:
```sh
sh -c "$(curl -sSL https://git.io/install-kubent)"
```
*(Unless specified the script will download latest version and unpack to `/usr/local/bin/`).*
> Note: Do not run random scripts from strangers on the internet. Read what the above script does first.
### Manual Installation
You can download the
[latest release](https://github.com/doitintl/kube-no-trouble/releases/latest)
for your cpu architectures and operating system. You can then place it on your path.
We currently maintain, the following operating systems and cpu architectures:
- Linux amd64
- Linux arm64
- Darwin amd64
- Darwin arm64
- Windows amd64
*Historically Windows on arm, has not received the best support. If this changes we may add it.*
### Third-Party Installation
Please note that third-party installation methods are maintained by the community.
**The packages may not always be up-to-date with the latest releases of** `kubent`.
#### Homebrew
`kubent` is available as a [formula](https://formulae.brew.sh/formula/kubent)
on [Homebrew](https://brew.sh/). If you're using macOS or Linux, you can run
the following command to install `kubent`:
```sh
brew install kubent
```
#### Scoop
`kubent` is available for [Scoop](https://scoop.sh/) as an [app](https://bjansen.github.io/scoop-apps/main/kubent/).
Install `kubent` by running:
```powershell
scoop install kubent
```
## Usage
Configure Kubectl's current context to point to your cluster, `kubent` will
look for the kube `.config` file in standard locations (you can point it to custom
location using the `-k` switch).
**`kubent`** will collect resources from your cluster and report on found issues.
*Please note that you need to have sufficient permissions to read Secrets in the
cluster in order to use `Helm*` collectors.*
```sh
$./kubent
6:25PM INF >>> Kube No Trouble `kubent` <<<
6:25PM INF Initializing collectors and retrieving data
6:25PM INF Retrieved 103 resources from collector name=Cluster
6:25PM INF Retrieved 0 resources from collector name="Helm v3"
6:25PM INF Loaded ruleset name=deprecated-1-16.rego
6:25PM INF Loaded ruleset name=deprecated-1-20.rego
__________________________________________________________________________________________
>>> 1.16 Deprecated APIs <<<
------------------------------------------------------------------------------------------
KIND NAMESPACE NAME API_VERSION
Deployment default nginx-deployment-old apps/v1beta1
Deployment kube-system event-exporter-v0.2.5 apps/v1beta1
Deployment kube-system k8s-snapshots extensions/v1beta1
Deployment kube-system kube-dns extensions/v1beta1
__________________________________________________________________________________________
>>> 1.20 Deprecated APIs <<<
------------------------------------------------------------------------------------------
KIND NAMESPACE NAME API_VERSION
Ingress default test-ingress extensions/v1beta1
```
### Arguments
You can list all the configuration options available using `--help` switch:
```sh
$./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
```
- *`--additional-annotation`*
Check additional annotations for the last applied configuration. This can be useful if a resource was applied
with a tool other than kubectl. The flag can be used multiple times.
- *`-a, --additional-kind`*
Tells `kubent` to flag additional custom resources when found in the specified version. The flag can be used multiple
times. The expected format is full *Kind.version.group.com* form - e.g. `-a ManagedCertificate.v1.networking.gke.io`.
- *`-x, --context`*
Select context from kubeconfig file (`current-context` from the file is used by default).
- *`-k, --kubeconfig`*
Path to kubeconfig file to use. This takes precedence over `KUBECONFIG` environment variable, which is also supported
and can contain multiple paths, and default `~/.kube/config`.
- *`-t, --target-version`*
`kubent` will try to detect K8S cluster version and display only relevant findings. This flag allows to override this
version for scenarios like use in CI with the file collector only, when detection from an actual cluster is not possible.
Expected format is `major.minor[.patch]`, e.g. `1.16` or `1.16.3`.
### Docker Image
We also publish official container image, which can be found at:
`ghcr.io/doitintl/kube-no-trouble:latest` (also available tagged with each
individual release version).
To run locally, you'll need to provide credentials, e.g. by sharing your
kubectl config:
```sh
$ docker run -it --rm \
-v "${HOME}/.kube/config:/.kubeconfig" \
ghcr.io/doitintl/kube-no-trouble:latest \
-k /.kubeconfig
```
You can use `kubectl run` to run inside a K8S cluster, as a one-off. In that
case the credentials will be picked up via the pod's service account from the
environment, but you'll want to grant relevant permissions first (see
[docs/k8s-sa-and-role-example.yaml](docs/k8s-sa-and-role-example.yaml)):
```sh
$ kubectl run kubent --restart=Never --rm -i --tty \
--image ghcr.io/doitintl/kube-no-trouble:latest \
--overrides='{"spec": {"serviceAccount": "kubent"}}'
```
### Use in CI
#### Exit codes
`kubent` will by default return `0` exit code if the program succeeds, even if
it finds deprecated resources, and non-zero exit code if there is an error
during runtime. Because all info output goes to stderr, it's easy to check in
shell if any issues were found:
```shell
test -z "$(kubent)" # if stdout output is empty, means no issues were found
# equivalent to [ -z "$(kubent)" ]
```
It's actually better so split this into two steps, in order to differentiate
between runtime error and found issues:
```shell
if ! OUTPUT="$(kubent)"; then # check for non-zero return code first
echo "kubent failed to run!"
elif [ -n "${OUTPUT}" ]; then # check for empty stdout
echo "Deprecated resources found"
fi
```
You can also use `--exit-error` (`-e`) flag, which will make kubent to exit
with non-zero return code (`200`) in case any issues are found.
Alternatively, use the json output and smth. like `jq` to check if the result is
empty:
```
kubent -o json | jq -e 'length == 0'
```
#### Scanning all files in directory
If you want to scan all files in a given directory, you can use the following
shell snippet:
```shell
FILES=($(ls *.yaml)); kubent ${FILES[@]/#/-f} --helm3=false -c=false
```
## Development
The simplest way to build `kubent` is:
```sh
# Clone the repository
git clone https://github.com/doitintl/kube-no-trouble.git
cd kube-no-trouble/
# Build
go build -o bin/kubent ./...
```
Otherwise there's `Makefile`
```sh
$ make
make
all Clean, build and pack
help Prints list of tasks
build Build binary
generate Go generate
release-artifacts Create release artifacts
clean Clean build artifacts
```
## Issues and Contributions
Please open any issues and/or PRs against github.com/doitintl/kube-no-trouble repository. See our [contribution guide](.github/CONTRIBUTING.md) for more details
", Assign "at most 3 tags" to the expected json: {"id":"3069","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"