Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support of Pod Autoscaling API #227

Closed
hridyeshpant opened this issue Feb 14, 2017 · 5 comments
Closed

support of Pod Autoscaling API #227

hridyeshpant opened this issue Feb 14, 2017 · 5 comments

Comments

@hridyeshpant
Copy link

kubectl provide Pod Autoscaling

deployment "php-apache" autoscaled```

Do we have such API in kubeclient?
@cben
Copy link
Collaborator

cben commented Apr 18, 2017

You can use kubectl --loglevel=11 to see the API requests and responses involved (the actual max level is more like 5, I never remember exactly so I like setting it up to 11 ;-).
I suppose it's using /apis/autoscaling/v1/namespaces/{namespace}/horizontalpodautoscalers/{name}?
https://kubernetes.io/docs/api-reference/v1.6/#horizontalpodautoscaler-v1-autoscaling

In theory kubeclient should now support any resource in any API group.
Can you something like Kubeclient::Client.new('http://localhost:8080/apis', 'autoscaling/v1', options)?

@cben cben added the question label Mar 4, 2018
@cben
Copy link
Collaborator

cben commented Mar 4, 2018

Hi, is this still a problem? Have you tried with an API group?

@cben
Copy link
Collaborator

cben commented May 27, 2018

Works for me, details below.
You're far from the first to ask how to use a non-default API group.
If you see a way to improve README so this would be clearer, please send a PR or just suggestions!


$ oc autoscale -n mynamespace dc/postgresql --max=1
deploymentconfig "postgresql" autoscaled
$ oc get horizontalpodautoscalers -n mynamespace
NAME         REFERENCE                     TARGETS           MINPODS   MAXPODS   REPLICAS   AGE
postgresql   DeploymentConfig/postgresql   <unknown> / 80%   1         1         1          3m

Then in ruby:
EDIT: this was wrong way to initialize Client, see the comment below this one.

client = Kubeclient::Client.new('http://master.example.com:8443/apis', 'autoscaling/v1', options)
client.get_horizontal_pod_autoscalers
as = c.get_horizontal_pod_autoscaler("postgresql", "mynamespace")
# => #<Kubeclient::Resource kind="HorizontalPodAutoscaler", apiVersion="autoscaling/v1", metadata={:name=>"postgresql", :namespace=>"mynamespace", :selfLink=>"/apis/autoscaling/v1/namespaces/mynamespace/horizontalpodautoscalers/postgresql", :uid=>"0f950927-61c4-11e8-a369-42010a8e0002", :resourceVersion=>"55349", :creationTimestamp=>"2018-05-27T15:38:53Z", :annotations=>{:"autoscaling.alpha.kubernetes.io/conditions"=>"[{\"type\":\"AbleToScale\",\"status\":\"True\",\"lastTransitionTime\":\"2018-05-27T15:39:23Z\",\"reason\":\"SucceededGetScale\",\"message\":\"the HPA controller was able to get the target's current scale\"},{\"type\":\"ScalingActive\",\"status\":\"False\",\"lastTransitionTime\":\"2018-05-27T15:39:23Z\",\"reason\":\"FailedGetResourceMetric\",\"message\":\"the HPA was unable to compute the replica count: unable to get metrics for resource cpu: failed to get pod resource metrics: the server could not find the requested resource (get services https:heapster:)\"}]"}}, spec={:scaleTargetRef=>{:kind=>"DeploymentConfig", :name=>"postgresql", :apiVersion=>"v1"}, :minReplicas=>1, :maxReplicas=>1, :targetCPUUtilizationPercentage=>90}, status={:currentReplicas=>1, :desiredReplicas=>0}>

as.spec.targetCPUUtilizationPercentage
# => 80
as.spec.targetCPUUtilizationPercentage = 90
c.update_horizontal_pod_autoscaler(as)
$ oc get horizontalpodautoscalers -n mynamespace
NAME         REFERENCE                     TARGETS           MINPODS   MAXPODS   REPLICAS   AGE
postgresql   DeploymentConfig/postgresql   <unknown> / 90%   1         1         1          2m

Mimicking kubectl autoscale would require create_horizontal_pod_autoscaler with proper content yourself.

Note this object now also has v2beta1 version "which includes support for scaling on memory and custom metrics":
https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#horizontalpodautoscaler-v1-autoscaling
https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#horizontalpodautoscaler-v2beta1-autoscaling
https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#api-object

@cben
Copy link
Collaborator

cben commented May 31, 2018

Correction, please don't do:

Kubeclient::Client.new('http://master.example.com:8443/apis', 'autoscaling/v1', options)

even if that makes sense and appears to work (?), but instead do:

Kubeclient::Client.new('http://master.example.com:8443/apis/autoscaling', 'v1', options)

This is silly (#284, #318) but this is the current documented interface.

@cben
Copy link
Collaborator

cben commented Jan 23, 2019

I believe this works and I've answered the question, feel free to reopen if still a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants