Sub topic 5
Finding deprecated API usage before it breaks
This chapter assumes you can use kubectl, read YAML manifests, and know what Ingress, Deployment, and CronJob objects do. It also assumes you know that API versions have maturity levels and that old versions are eventually removed.
Two places to look
Deprecated API usage appears in two places. Manifests in your repositories show what you will apply later. Live traffic to the API server shows what clients are calling right now, including Helm releases, controllers, and scripts that you may not remember.
You need both views. A clean repository does not prove that no running tool still calls a removed version.
Checking a running cluster
The API server records every request that uses a deprecated API version. It exposes this as the apiserver_requested_deprecated_apis metric. Each series carries the labels group, version, resource, and removed_release. The last label names the release where that version goes away.
# Show which deprecated APIs this API server has served requests for
kubectl get --raw /metrics | grep apiserver_requested_deprecated_apis
# List the API versions the server currently serves
kubectl api-versions | sortCompare removed_release with the version you plan to upgrade to. A line with removed_release="1.22" is a problem for any upgrade to 1.22 or later.
The metric tells you that something called the API, but not who. To find the caller, check API server audit logs, which record the user agent and user for each request.
Reading a failing manifest
Here is an Ingress that uses extensions/v1beta1. Kubernetes 1.22 removed this version, so a cluster at or above 1.22 rejects it.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: web
spec:
rules:
- host: example.com
http:
paths:
- path: /
backend:
serviceName: web
servicePort: 80Applying this to a 1.22 cluster fails because the server no longer serves that version. The serviceName and servicePort fields also belong to the old schema. The next chapter covers the replacement.
Limits of the metric
- It is per API server. With several control plane nodes, query each one. A request may have reached a different instance.
- It resets on restart. The counters start over when the API server restarts, so a quiet period after a restart proves little.
- It only sees traffic. A CronJob that runs once a month will not appear until it calls the API. Check such manifests in Git as well.
A practical routine
- Run the metrics query on every control plane node and collect the results.
- Note each
removed_releasevalue that is at or below your target version. - Search audit logs or repositories for the owners of those calls.
- Add the affected manifests to a migration list.
Exercise
Your metrics query shows a line with removed_release="1.25" and you plan to upgrade from 1.24 to 1.25. Is the upgrade safe for that API, and why or why not?
Show answer
No. The API version is removed in 1.25, so any client or manifest that still uses it will fail after the upgrade. You must migrate those clients and manifests first.