def kubectl_install(self): self.logger.info("Execute the script to install kubectl on your host!") commandline = "./deployment/k8sPaiLibrary/maintaintool/kubectl-install.sh" common.execute_shell(commandline, "Failed to install kubectl on your dev-box") self.logger.info("Successfully install kubectl on the dev-box.")
def create_k8s_dashboard(self): self.logger.info( "Create kubernetes dashboard deployment for kuberentes cluster.") self.logger.info("Create dashboard service.") file_path = "k8sPaiLibrary/template/dashboard-service.yaml.template" template_data = common.read_template(file_path) dict_map = {"clusterconfig": self.cluster_config['clusterinfo']} generated_data = common.generate_from_template_dict( template_data, dict_map) common.write_generated_file(generated_data, "dashboard-service.yaml") common.execute_shell("kubectl create -f dashboard-service.yaml", "Failed to create dashboard-service") os.remove("dashboard-service.yaml") self.logger.info("Create dashboard deployment.") file_path = "k8sPaiLibrary/template/dashboard-deployment.yaml.template" template_data = common.read_template(file_path) dict_map = {"clusterconfig": self.cluster_config['clusterinfo']} generated_data = common.generate_from_template_dict( template_data, dict_map) common.write_generated_file(generated_data, "dashboard-deployment.yaml") common.execute_shell("kubectl create -f dashboard-deployment.yaml", "Failed to create dashboard-deployment") os.remove("dashboard-deployment.yaml")
def job_executer(self): self.logger.info("{0} job begins !".format(self.jobname)) commandline = "kubectl delete node {0}".format( self.node_config['nodename']) common.execute_shell( commandline, "Failed to delete node {0}".format(self.node_config['nodename'])) # sftp your script to remote host with paramiko. srcipt_package = "{0}.tar".format(self.jobname) src_local = "parcel-center/{0}".format(self.node_config["nodename"]) dst_remote = "/home/{0}".format(self.node_config["username"]) if common.sftp_paramiko(src_local, dst_remote, srcipt_package, self.node_config) == False: return commandline = "tar -xvf {0}.tar".format(self.jobname, self.node_config['hostip']) if common.ssh_shell_paramiko(self.node_config, commandline) == False: self.logger.error("Failed to uncompress {0}.tar".format( self.jobname)) return commandline = "sudo ./{0}/kubernetes-cleanup.sh".format(self.jobname) if common.ssh_shell_paramiko(self.node_config, commandline) == False: self.logger.error( "Failed to cleanup the kubernetes deployment on {0}".format( self.node_config['hostip'])) return self.logger.info("Successfully running {0} job on node {1}".format( self.jobname, self.node_config["nodename"]))
def create_k8s_dashboard(self): com = self.cluster_object_model self.logger.info( "Create kubernetes dashboard deployment for kuberentes cluster.") self.logger.info("Create dashboard service.") file_path = "deployment/k8sPaiLibrary/template/dashboard-service.yaml.template" template_data = common.read_template(file_path) dict_map = {"cluster_cfg": com} generated_data = common.generate_from_template_dict( template_data, dict_map) common.write_generated_file(generated_data, "dashboard-service.yaml") retry_count = 5 common.execute_shell_retry( "kubectl apply --overwrite=true -f dashboard-service.yaml", "Failed to create dashboard-service", retry_count) os.remove("dashboard-service.yaml") self.logger.info("Create dashboard deployment.") file_path = "deployment/k8sPaiLibrary/template/dashboard-deployment.yaml.template" template_data = common.read_template(file_path) dict_map = {"cluster_cfg": com} generated_data = common.generate_from_template_dict( template_data, dict_map) common.write_generated_file(generated_data, "dashboard-deployment.yaml") common.execute_shell( "kubectl apply --overwrite=true -f dashboard-deployment.yaml", "Failed to create dashboard-deployment") os.remove("dashboard-deployment.yaml")
def create_kube_proxy(self): self.logger.info("Create kube-proxy daemon for kuberentes cluster.") file_path = "k8sPaiLibrary/template/kube-proxy.yaml.template" template_data = common.read_template(file_path) dict_map = {"clusterconfig": self.cluster_config['clusterinfo']} generated_data = common.generate_from_template_dict( template_data, dict_map) common.write_generated_file(generated_data, "kube-proxy.yaml") common.execute_shell("kubectl create -f kube-proxy.yaml", "Failed to create kube-proxy") os.remove("kube-proxy.yaml")