Python kubernetes.client.AutoscalingV1Api() Examples
The following are 4
code examples of kubernetes.client.AutoscalingV1Api().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
kubernetes.client
, or try the search function
.
Example #1
Source File: k8s_manage.py From sparrow with GNU General Public License v3.0 | 6 votes |
def modify_k8s_hpa(): infos = None status = None try: Infos = request.get_json() api_instance = client.AutoscalingV1Api() if request.method == 'POST': try: api_instance.patch_namespaced_horizontal_pod_autoscaler(name=Infos['name'], namespace=namespace, body=client.V1HorizontalPodAutoscaler( spec=client.V1HorizontalPodAutoscalerSpec( max_replicas=int(Infos['max_update']), target_cpu_utilization_percentage=int(Infos['cpu_update'].replace('%','')), scale_target_ref=client.V1CrossVersionObjectReference( kind='Deployment', name=Infos['target_ref'])))) except Exception as e: logging.error(e) infos = '修改参数失败!' else: status = 'ok' infos = '修改参数成功!' if request.method == 'DELETE': try: api_instance.delete_namespaced_horizontal_pod_autoscaler(name=Infos['name'], namespace=namespace,body=client.V1DeleteOptions()) except Exception as e: logging.error(e) infos = '删除%s失败!' %Infos['name'] else: status = 'ok' infos = '删除%s成功!' %Infos['name'] except Exception as e: logging.error(e) finally: return jsonify({'status':status,'infos':infos})
Example #2
Source File: client.py From kube-shell with Apache License 2.0 | 5 votes |
def __init__(self): self.logger = logging.getLogger(__name__) try: config_file = os.path.expanduser(kubeconfig_filepath) config.load_kube_config(config_file=config_file) except: self.logger.warning("unable to load kube-config") self.v1 = client.CoreV1Api() self.v1Beta1 = client.AppsV1beta1Api() self.extensionsV1Beta1 = client.ExtensionsV1beta1Api() self.autoscalingV1Api = client.AutoscalingV1Api() self.rbacApi = client.RbacAuthorizationV1beta1Api() self.batchV1Api = client.BatchV1Api() self.batchV2Api = client.BatchV2alpha1Api()
Example #3
Source File: kubernetes_utils.py From tacker with Apache License 2.0 | 5 votes |
def get_scaling_api_client(self, auth): k8s_client = self.get_k8s_client(auth_plugin=auth) return client.AutoscalingV1Api(api_client=k8s_client)
Example #4
Source File: k8s_deploy.py From sparrow with GNU General Public License v3.0 | 4 votes |
def hpa_apply(): try: reload(MyForm) form = MyForm.FormK8sHpa() if form.submit.data: context = form.contexts.data deployment = form.deployment.data max_replica = form.max_replica.data min_replica = form.min_replica.data cpu_value = form.cpu_value.data if max_replica and min_replica and cpu_value: exist_hpa = [] config.load_kube_config(config_file,context) api_instance = client.AutoscalingV1Api() try: ret = api_instance.list_horizontal_pod_autoscaler_for_all_namespaces() for i in ret.items: exist_hpa.append(i.spec.scale_target_ref.name) if deployment in exist_hpa: #配置已存在进行更新 api_instance.patch_namespaced_horizontal_pod_autoscaler( name='%s-hpa'%deployment, namespace=namespace, body=client.V1HorizontalPodAutoscaler( spec=client.V1HorizontalPodAutoscalerSpec( max_replicas=int(max_replica), min_replicas=int(min_replica), target_cpu_utilization_percentage=int(cpu_value), scale_target_ref=client.V1CrossVersionObjectReference( api_version='extensions/v1beta1', kind='Deployment', name=deployment)) )) else: # 配置不存在进行创建 api_instance.create_namespaced_horizontal_pod_autoscaler( namespace=namespace, body=client.V1HorizontalPodAutoscaler( metadata=client.V1ObjectMeta( name='%s-hpa'%deployment, namespace=namespace), spec=client.V1HorizontalPodAutoscalerSpec( max_replicas=int(max_replica), min_replicas=int(min_replica), target_cpu_utilization_percentage=int(cpu_value), scale_target_ref=client.V1CrossVersionObjectReference( api_version='extensions/v1beta1', kind='Deployment', name=deployment)) )) return redirect(url_for('k8s.hpa')) except Exception as e: logging.error(e) except Exception as e: logging.error(e) return redirect(url_for('error')) return render_template('k8s_hpa.html', form=form)