Kubernetes - API Versions & Resources
When I sat down to write this article, it was originally titled Top 4 things that confused me about Kubernetes. However, as I began writing it, I realized that putting all 4 of my confusing things into one article would be entirely too much information. It needed to be broken up. So, here is part one, understanding the different API Versions & API Resources of Kubernetes.
At a high level, Kubernetes resources fall under one of two different API groups. There is the core (aka legacy) group and there is also the collection of named groups.
The Core Group
This is the original group of resources. It includes popular resources like Pods, Nodes, Namespaces, Services, and more. When you access the Kubernetes REST API, you can reference a resource from the Core Group using /api/v1. Likewise, when creating resource definition YAML files, you reference a resource from the Core Group by using the field apiVersion: v1 at the top of the file.
The Named Groups
As Kubernetes has evolved, so has its API. Newer types of resources can be found under their own Named Groups of APIs. For example, a Deployment falls under the Apps/v1 API Group. When you access the Kubernetes REST API, you can reference a resource from a Named Group by using this syntax /apis/groupName/version (notice the "s" in apis, which is different from the Core Group, which uses just api). When creating resource definition YAML files, you reference a resource from the Named Groups by using the field apiVersion: groupName/version at the top of the file.
There are many different Named Groups, and each group contains 1 or more different types of Kubernetes resources.
Some useful kubectl commands
This command prints the supported API resources on the server. You'll notice that this command also gives you a lot of extra information. You'll see if a resource has a shortname, so you can type "csr" instead of "CertificateSigningRequest." You'll see the API Group that each resource is attached to, whether that's the Core Group or one of the Named Groups. You'll see if each resource is tied to a Namespace or not. Finally, you'll see the exact name to use for the "kind" field in your resource definition YAML files.
This command prints the supported API versions on the server, in the form of "group/version." This shows you all of the API groups that are supported on the server. It pulls info from both the Core Group & all of the Named Groups.