def start_dashboard(): print("starting kube-dashboard.") cmd("kubectl create -f {}sa-admin-user.yaml".format(_script_dir)) cmd("kubectl create -f {}sa-clusterrolebinding-admin-user.yaml".format(_script_dir)) cmd("kubectl create -f https://raw.githubusercontent.com/" "kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml") import time time.sleep(5) cmd("kubectl proxy >> ~/log/kube-build.log 2>&1 &") cmd("kubectl -n kube-system describe secret " "$(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')") print("done.")
def port(): # TODO: better way of getting the prometheus pod cmd("pkill kubectl || true") cmd("kubectl port-forward -n monitoring " "$(kubectl get pods -n monitoring -o name | grep prometheus-deployment | cut -d \"/\" -f2) " "{}:{} &>/dev/null &" .format(cg.prometheus_server_port, cg.prometheus_server_port)) # TODO: replace the keep-alive with kubelet configurations to hold the tunnel cmd("watch -n120 curl localhost:{} &> /dev/null &".format(cg.prometheus_server_port)) print("port forwarding completed.")
def cmd_with_bash(command): cmd("bash {}".format(command))
def stop_monitor(): prometheus_path = _dir_path + "/../../thirdparty/prometheus" cmd("cd {}/contrib/kube-prometheus/; ./hack/cluster-monitoring/teardown".format(prometheus_path))
def start_metric_server(): metric_server_path = _dir_path + "/../metrics-server" cmd("kubectl create -f {}/deploy/1.8+/".format(metric_server_path))
def start_prometheus_operator(): cmd("kubectl apply -f https://raw.githubusercontent.com/kubernetes" "/kops/master/addons/prometheus-operator/v0.19.0.yaml --validate=false") cmd("kubectl get pods -n monitoring")
def start_monitor(): prometheus_path = _dir_path + "/prometheus" cmd("kubectl create namespace monitoring; kubectl apply -f {}".format(prometheus_path))
def install_schedulers(): cmd("kubectl create -f {}".format(_dir_path + "/scheduler/origin-scheduler.yaml")) cmd("kubectl create -f {}".format(_dir_path + "/scheduler/image-scheduler.yaml"))
def make(): cmd("cd {}; source env.exp; cd ${{KUBE_ROOT}}; " "make quick-release".format(_script_dir))
def validate_svc(): cmd("kubectl get svc -n kube-system")
def get_dashboard_token(): cmd("kubectl -n kube-system describe secret " "$(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')")
def export_cluster(): cmd(_script_dir + "export.sh")
def edit_cluster(): cmd("source {}; kops edit ig nodes; kops update cluster $NAME --yes; kops rolling-update cluster --yes".format( _script_dir + "env.exp"))
def update_cluster(): # update the cluster utils.cmd("source {}; kops update cluster --yes".format(_env_file))
def upload_ig(ig_config: dict, cmd): temp_file = "/tmp/" + utils.uuid_str() with open(temp_file, "w") as f: f.write(utils.yaml_dump_str(ig_config)) utils.cmd("source {}; kops {} -f {}".format(_env_file, cmd, temp_file)) utils.cmd("rm " + temp_file)