Why Does Kubernetes Have Both /api and /apis?
Read enough Kubernetes YAML and you start noticing a small oddity.
A Pod starts like this:
apiVersion: v1
kind: Pod
A Deployment doesn't:
apiVersion: apps/v1
kind: Deployment
A CronJob is different again:
apiVersion: batch/v1
kind: CronJob
Most of us just memorize this when we start out. Pod is v1, Deployment is apps/v1, move on. But why are they different?
Once you get the answer, you also get why the Kubernetes API Server has both /api and /apis.
Kubernetes is one giant REST API server
Day to day, we use Kubernetes like this:
kubectl get pods
But kubectl doesn't actually hold any Pod data. It's a client. All it does is send requests to the Kubernetes API Server.
Conceptually, it looks like this:
kubectl
↓
Kubernetes API Server
↓
API Group
↓
Version
↓
Resource
So the commands you run every day:
kubectl get pods
kubectl get deployments
kubectl get services
are all just requests against the Kubernetes API.
The API Server has to serve a huge number of resources. How does Kubernetes keep them organized? That's where API Groups come in.
What if you dumped every resource in one place?
Kubernetes has a lot of resources. Pod, Service, ConfigMap, Secret, Namespace, Deployment, StatefulSet, DaemonSet, Job, CronJob, Ingress, Role, ClusterRole… and once you start installing CRDs, the list gets much longer.
Imagine managing all of that in a single API space:
/v1/pods
/v1/services
/v1/deployments
/v1/jobs
/v1/roles
/v1/ingresses
...
Early on, that might be fine. As Kubernetes grows, it breaks down. Resources evolve at different speeds, and their API versions need to be managed independently.
So Kubernetes splits related APIs into groups. Something like this:
Core
├─ Pod
├─ Service
├─ ConfigMap
└─ Secret
apps
├─ Deployment
├─ StatefulSet
└─ DaemonSet
batch
├─ Job
└─ CronJob
networking.k8s.io
├─ Ingress
└─ NetworkPolicy
rbac.authorization.k8s.io
├─ Role
├─ RoleBinding
├─ ClusterRole
└─ ClusterRoleBinding
If you've built software, it's the same move as splitting one massive package into modules by domain.
One group is special
The Core API Group. This is where the most fundamental Kubernetes resources live: Pod, Service, ConfigMap, Secret, Namespace, PersistentVolume.
Here's the quirk. The Core Group has no name.
That's why a Pod's apiVersion isn't
apiVersion: core/v1
but
apiVersion: v1
The REST API follows the same rule. Core resources live under this path:
/api/v1
So listing Pods in the default Namespace through the API looks like this:
/api/v1/namespaces/default/pods
And for Services:
/api/v1/namespaces/default/services
/apis is where every named group lives
As Kubernetes grew, it picked up Deployments, Jobs, Ingress, RBAC, and more. Instead of piling all of that into the Core Group, each got its own named API Group.
The usual suspects:
apps
batch
networking.k8s.io
rbac.authorization.k8s.io
apiextensions.k8s.io
The easiest way to think about these is as Named API Groups.
Named API Groups live under /apis, with this shape:
/apis/{group}/{version}
Take a Deployment:
apiVersion: apps/v1
kind: Deployment
Here:
apps = API Group
v1 = API Version
So the REST path is
/apis/apps/v1
and listing Deployments in default becomes
/apis/apps/v1/namespaces/default/deployments
The YAML maps straight onto the REST API.
Pull apart apiVersion and you get an API address
Look at apiVersion again with that in mind and it means something else entirely.
Back to the Deployment:
apiVersion: apps/v1
kind: Deployment
Decoded:
Group = apps
Version = v1
Resource = deployments
Which maps to:
/apis/apps/v1/.../deployments
CronJob works the same way:
apiVersion: batch/v1
kind: CronJob
Decoded:
Group = batch
Version = v1
Resource = cronjobs
So the REST path is:
/apis/batch/v1/.../cronjobs
Ingress:
apiVersion: networking.k8s.io/v1
kind: Ingress
becomes
/apis/networking.k8s.io/v1/.../ingresses
apiVersion isn't a string you type out of habit. It's closer to an address: which API Group, and which version of it, should handle this resource.
Now /api vs /apis is trivial
Put it all together:
Kubernetes API Server
│
├── /api
│ └── Core API Group
│ └── v1
│ ├── pods
│ ├── services
│ ├── configmaps
│ └── secrets
│
└── /apis
└── Named API Groups
│
├── apps
│ └── v1
│ ├── deployments
│ ├── daemonsets
│ └── statefulsets
│
├── batch
│ └── v1
│ ├── jobs
│ └── cronjobs
│
└── networking.k8s.io
└── v1
├── ingresses
└── networkpolicies
The whole rule fits in two lines:
Core API Group
/api/{version}
Named API Group
/apis/{group}/{version}
One trap to avoid. The s in /apis doesn't mean a newer API. /api isn't the legacy path and /apis isn't the modern one. They're just separate REST paths for the Core group and the named groups.
It's more fun to check for yourself
If you have a cluster handy, ask the API Server directly:
kubectl get --raw /api
That shows the versions the Core API serves. For the named groups:
kubectl get --raw /apis
The output is long, so if you have jq:
kubectl get --raw /apis | jq
is much easier to read. You can also see what resources live in Core v1:
kubectl get --raw /api/v1 | jq
And apps/v1:
kubectl get --raw /apis/apps/v1 | jq
In practice, though, there's a much friendlier command:
kubectl api-resources
It shows an APIVERSION column. Roughly:
NAME APIVERSION
pods v1
services v1
deployments apps/v1
statefulsets apps/v1
jobs batch/v1
ingresses networking.k8s.io/v1
Now you know why those values differ.
When the Namespace is in the path, and when it isn't
There's one more piece you need for the REST paths to make sense. Kubernetes resources come in two flavors: Namespace-scoped and Cluster-scoped.
A Pod belongs to a Namespace, so the Namespace shows up in the path:
/api/v1/namespaces/default/pods
Deployments are namespaced too:
/apis/apps/v1/namespaces/default/deployments
A Node doesn't belong to any Namespace, so:
/api/v1/nodes
ClusterRole is cluster-scoped as well:
/apis/rbac.authorization.k8s.io/v1/clusterroles
So to reason about any REST path, you need three things:
API Group
API Version
Resource Scope
This also makes CRDs click
Go one step further and you start to see how extensible Kubernetes is. You're not limited to the built-in resources. With a CRD (CustomResourceDefinition), you can define new ones.
Say a platform team creates this Custom Resource:
apiVersion: database.example.com/v1
kind: Database
Same rules apply:
Group = database.example.com
Version = v1
So its API naturally lives under:
/apis/database.example.com/v1
A CRD isn't really a separate management system bolted on next to Kubernetes. It's a way to extend the Kubernetes API itself with a new resource type. That's a big part of why Kubernetes became a platform and not just a thing that runs containers.
When does this matter in operations?
Most days, you never have to think about /api vs /apis. kubectl handles it. Get into incident analysis or platform work, though, and it's a different story.
You might hit this:
the server could not find the requested resource
Instead of assuming the resource just isn't there, you start checking:
- Does this API Group exist?
- Is this version supported?
- Was the API deprecated or removed?
- Is the CRD registered correctly?
- Is the
apiVersionin my manifest supported by this cluster?
It matters a lot during Kubernetes upgrades too. When an API you relied on gets deprecated and then removed in a later release, your existing YAML can simply stop working.
Kubernetes YAML is an API request
When you learn Kubernetes, YAML is the first thing you touch. So it's easy to come away thinking Kubernetes is a system for writing endless YAML.
Look one layer down and the picture changes. The API Server sits at the center of Kubernetes. And what we write:
apiVersion:
kind:
metadata:
spec:
isn't just config file syntax. It's a declaration: use this API, for this kind of resource, and get it into this state.
To really understand Kubernetes, it helps to look at the structure under the YAML, not the YAML itself.
YAML
↓
apiVersion + kind
↓
API Group + Version + Resource
↓
REST API
↓
API Server
And the simplest entry point into that structure is this:
/api → Core API Group
/apis → Named API Groups
Why a Pod's apiVersion is plain v1. Why a Deployment is apps/v1. Why CRDs look like example.com/v1. Things that looked like trivia to memorize all fall out of one API design principle.
You can run Kubernetes for years without ever looking at /api or /apis directly. But once this small difference clicks, it gets a little clearer that Kubernetes isn't just a tool for launching containers from YAML. It's a large distributed system that abstracts every resource behind an API.
Was this post helpful?
One click helps me write the next one