Exemplo n.º 1
0
def query_k8s_replicas(endpoint,service_name):
  service_name = '-'.join(service_name.split('_')[1:])
  log=logging.getLogger('pk_k8s')
  instance = 1
  if pk_config.simulate():
    return
  kubernetes.config.load_kube_config()
  client = kubernetes.client.ExtensionsV1beta1Api()
  try:
    dep = client.read_namespaced_deployment(service_name, "default")
    replicas = dep.spec.replicas
    log.debug('(C) => m_container_count for {0}: {1}'.format(service_name,replicas))
  except Exception as e:
    log.warning('(C) Querying k8s service "{0}" replicas failed: {1}'.format(service_name,str(e)))
  return instance
Exemplo n.º 2
0
def scale_k8s_deploy(endpoint,service_name,replicas):
  service_name = '-'.join(service_name.split('_')[1:])
  log=logging.getLogger('pk_k8s')
  log.info('(S) => m_container_count: {0}'.format(replicas))
  if pk_config.simulate():
    return
  kubernetes.config.load_kube_config()
  client = kubernetes.client.ExtensionsV1beta1Api()
  try:
    dep = client.read_namespaced_deployment(service_name, "default")
    dep.spec.replicas = replicas
    client.patch_namespaced_deployment_scale(service_name, "default", dep)
  except Exception as e:
    log.warning('(S) Scaling of k8s service "{0}" failed: {1}'.format(service_name,str(e)))
  return