Why Does kubectl get Show a Different API Group for a Resource Than Specified?
This document (000020137) is provided subject to the disclaimer at the end of this document.
Situation
Sometimes, when you use the kubectl get
command to retrieve Kubernetes resources, the API group and version shown may differ from what you originally specified in the resource specification. For instance, you might create a Deployment resource using the apps/v1
API group, but when you check the resource with kubectl get deployment -o yaml
, it appears under the extensions/v1beta1
API group:
Original Deployment YAML:
apiVersion: apps/v1
kind: Deployment
[...]
Output of 'kubectl get deployment -o yaml':
apiVersion: extensions/v1beta1
kind: Deployment
[...]
Resolution
Kubernetes resources, like Deployments, can exist in multiple API groups. If you don't specify an API group and version when using kubectl
, it defaults to the first group listed in the Kubernetes API server's discovery documentation. In the current example, the Deployment resource is available under both the apps/v1
and extensions/v1beta1
API groups. For backward compatibility, the API server might list extensions/v1beta1
first.
To ensure that kubectl
retrieves the resource from the desired API group, you can fully qualify the resource type. For example, to get Deployment resources from the apps
API group, use ' kubectl get deployments.apps -o yaml'
. To specify a particular version, you can use ' kubectl get deployments.v1.apps -o yaml'
.
Cause
The issue arises because Kubernetes resources can exist in multiple API groups and versions. If you don't specify the API group and version when using kubectl
, it defaults to the first group listed in the API server's discovery documentation. This can lead to the resource being displayed under a different API group or version than originally specified, mainly due to backward compatibility.
Additional Information
For more details on this behavior, you can check the Kubernetes GitHub Issue #58131.
The Kubernetes developer documentation on API resource versioning provides additional insights and can be found here.
Disclaimer
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.