A Confusing Aspect of the Kubernetes API Explained

$ kubectl version                               
Client Version: version.Info{Major:"1", Minor:"20+", GitVersion:"v1.20.8-dispatcher", GitCommit:"283881f025da4f5b3cefb6cd4c35f2ee4c2a79b8", GitTreeState:"clean", BuildDate:"2021-09-14T05:14:54Z", GoVersion:"go1.15.13", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"20+", GitVersion:"v1.20.9-gke.1001", GitCommit:"1fe18c314ed577f6047d2712a9d1c8e498e22381", GitTreeState:"clean", BuildDate:"2021-08-23T23:06:28Z", GoVersion:"go1.15.13b5", Compiler:"gc", Platform:"linux/amd64"}

The Confusing Aspect

$ kubectl get hpa debug -o yaml
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
...
name: debug
namespace: default
...
spec:
maxReplicas: 3
minReplicas: 2
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: debug
targetCPUUtilizationPercentage: 80
status:
currentCPUUtilizationPercentage: 1
currentReplicas: 2
desiredReplicas: 2
  • While the apiVersion in the manifest is autoscaling/v2beta2, the output shows the Resource as being apiVersion autoscaling/v1
  • The output does not show the behavior feature that we specified

API Groups, API Versions, and Resource Types

$ kubectl get --raw /apis | jq
{
"kind": "APIGroupList",
"apiVersion": "v1",
"groups": [
...
{
"name": "autoscaling",
"versions": [
{
"groupVersion": "autoscaling/v1",
"version": "v1"
},
{
"groupVersion": "autoscaling/v2beta1",
"version": "v2beta1"
},
{
"groupVersion": "autoscaling/v2beta2",
"version": "v2beta2"
}
],
"preferredVersion": {
"groupVersion": "autoscaling/v1",
"version": "v1"
}
},
...
$ kubectl get --raw /apis/autoscaling/v1 | jq       
{
"kind": "APIResourceList",
"apiVersion": "v1",
"groupVersion": "autoscaling/v1",
"resources": [
{
"name": "horizontalpodautoscalers",
"singularName": "",
"namespaced": true,
"kind": "HorizontalPodAutoscaler",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"hpa"
],
"categories": [
"all"
],
"storageVersionHash": "oQlkt7f5j/A="
},
{
"name": "horizontalpodautoscalers/status",
"singularName": "",
"namespaced": true,
"kind": "HorizontalPodAutoscaler",
"verbs": [
"get",
"patch",
"update"
]
}
]
}
  • By querying the v2beta1 and v2beta2 endpoints, we see that they also support horizontalpodautoscalers Resource Types
$ kubectl get hpa.v2beta2.autoscaling debug -o yaml
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
...
name: debug
namespace: default
...
spec:
behavior:
scaleDown:
policies:
- periodSeconds: 60
type: Pods
value: 4
- periodSeconds: 60
type: Percent
value: 10
selectPolicy: Max
scaleUp:
policies:
- periodSeconds: 15
type: Pods
value: 4
- periodSeconds: 15
type: Percent
value: 100
selectPolicy: Max
stabilizationWindowSeconds: 0
maxReplicas: 3
metrics:
- resource:
name: cpu
target:
averageUtilization: 80
type: Utilization
type: Resource
minReplicas: 2
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: debug
...
$ kubectl describe hpa debug
Name: debug
Namespace: default
Labels: <none>
Annotations: <none>
CreationTimestamp: Sat, 09 Oct 2021 15:45:36 -0400
Reference: Deployment/debug
Metrics: ( current / target )
resource cpu on pods (as a percentage of request): 1% (1m) / 80%
Min replicas: 2
Max replicas: 3
Behavior:
Scale Up:
Stabilization Window: 0 seconds
Select Policy: Max
Policies:
- Type: Pods Value: 4 Period: 15 seconds
- Type: Percent Value: 100 Period: 15 seconds
Scale Down:
Select Policy: Max
Policies:
- Type: Pods Value: 4 Period: 60 seconds
- Type: Percent Value: 10 Period: 60 seconds
Deployment pods: 2 current / 2 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True ReadyForNewScale recommended size matches current size
ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from cpu resource utilization (percentage of request)
ScalingLimited True TooFewReplicas the desired replica count is less than the minimum replica count
Events: <none>

Wrap Up

--

--

--

Broad infrastructure, development, and soft-skill background

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Flutter SignIn with LinkedIn.

Aggregation in JAVA

Claim Form — Group Life, Health and Dental Insurance

Three Questions to Move a Conversation from Philosophical to Practical

What is a server?

Always try to be part of something.

DatSetuSeSetupStep by step guide to install Atlassian Bamboo

Bamboo Systems Requirements — Source: https://confluence.atlassian.com/bamboo/bamboo-best-practice-system-requirements-388401

My experience in Flatiron School During & After : During

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
John Tucker

John Tucker

Broad infrastructure, development, and soft-skill background

More from Medium

Kubernetes Stateful Deployments

A relative between local environment and Kubernetes

Kubernetes Analogy Series: Authentication vs Authorization vs Admission Controller

Rotating etcd Encryption Key In Kubernetes