Exemplo n.º 1
0
    def validDashboard(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')

        #list pod and service
        cmdRemote = remoteBinPath + "/kubectl get pod,svc -n kube-system -o wide"
        robj_admin.sudo(cmdRemote)

        #cluster info
        cmdRemote = remoteBinPath + "/kubectl cluster-info -n kube-system"
        robj_admin.sudo(cmdRemote)

        #list tokens of kube-system namespaces
        cmdRemote = remoteBinPath + "/kubectl -n kube-system get secret"
        robj_admin.sudo(cmdRemote)

        #get token name to login
        cmdRemote = remoteBinPath + "/kubectl -n kube-system get secret"
        cmdRemote = cmdRemote + " | grep kubernetes-dashboard-token | awk '{print $1}'"
        robj_admin.sudo(cmdRemote)
        secretName = robj_admin.getResult().stdout.rstrip()
        # print(secretName)

        cmdRemote = remoteBinPath + "/kubectl -n kube-system describe secret " + secretName
        robj_admin.sudo(cmdRemote)
Exemplo n.º 2
0
    def validKbsNode(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')
        # remoteDemoPath = self.getRemotePath('remoteDemoPath')
        # kbsConfigPath = self.getLocalPath('kbsConfigPath')

        print("show csr info: ")
        cmdRemote = remoteBinPath + "/kubectl get csr"
        robj_admin.sudo(cmdRemote)
        print("pass tls request: ")
        cmdRemote = remoteBinPath + "/kubectl get csr | grep 'Pending'"
        cmdRemote = cmdRemote + " | awk 'NR>0 {print $1}'"
        cmdRemote = cmdRemote + " | xargs " + remoteBinPath + "/kubectl certificate approve"
        robj_admin.sudo(cmdRemote)

        #delete old anonymous role binding in master1
        cmdRemote = remoteBinPath + "/kubectl delete clusterrolebinding/cluster-system-anonymous"
        robj_admin.sudo(cmdRemote)

        #create role binding in master1
        cmdRemote = remoteBinPath + "/kubectl create clusterrolebinding cluster-system-anonymous"
        cmdRemote = cmdRemote + " --clusterrole=cluster-admin"
        cmdRemote = cmdRemote + " --user=system:anonymous"
        robj_admin.sudo(cmdRemote)

        print("show cluster nodes info: ")
        cmdRemote = remoteBinPath + "/kubectl get node -o wide"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 3
0
def sudo(c, cmd, nodename):

    # 初始化远程工具对象
    robj = Remote(getEnv(nodename))
    robj.sudo(cmd)

    print("Exec Success.")
Exemplo n.º 4
0
    def installWeaveNodeAfter(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        weaveConfigPath = self.getLocalPath('weaveConfigPath')
        remotePluginPath = self.getRemotePath('remotePluginPath')
        remoteBinPath = self.getRemotePath('remoteBinPath')

        tmpPath = self.getLocalPath('tmpPath')

        cmdRemote = remoteBinPath + "/kubectl delete -f " + remotePluginPath + "/weave/weave.yaml"
        robj_admin.sudo(cmdRemote)

        #upload yaml file
        ips_data = self.config_object.get_node_by_attr("name", "ips")
        podClusterIpRange = ips_data.find('podClusterIpRange').text.replace(
            "/", "\/")

        sedRegex = "sed \"s/{podClusterIpRange}/%s/g\"" % podClusterIpRange

        file_tmp = tmpPath + "/weave.yaml"
        file_config = weaveConfigPath + "/weave.yaml"
        cmd_local = "cat %s | %s > %s" % (file_config, sedRegex, file_tmp)
        robj_admin.local(cmd_local)

        # 上传文件到远程主机
        robj_admin.upload(file_tmp, remotePluginPath + "/weave/", True)

        #install weave plugin
        # yamlWeave="https://cloud.weave.works/k8s/net?k8s-version=\$(${remoteBinPath}/kubectl version | base64 | tr -d '\\\n')"
        cmdRemote = remoteBinPath + "/kubectl apply -f " + remotePluginPath + "/weave/weave.yaml"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 5
0
    def installWeaveNodeNormal(self, nodename):
        node_env = self.getEnv(nodename)
        # 初始化远程工具对象
        robj_node = Remote(node_env)

        #install bridge tools
        cmdRemote = "yum install -y bridge-utils"
        robj_node.sudo(cmdRemote)
Exemplo n.º 6
0
    def validCniNodeNormal(self, nodename):
        node_env = self.getEnv(nodename)
        # 初始化远程工具对象
        robj_node = Remote(node_env)

        print("check kubelet service ...")
        cmdRemote = "systemctl status kube-kubelet.service"
        robj_node.sudo(cmdRemote)
Exemplo n.º 7
0
    def validDemoDockerPrivate(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')

        #view
        cmdRemote = remoteBinPath + "/kubectl get pods busybox-demo -o wide"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 8
0
    def deleteDockerPrivate(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')
        remoteCfgPath = self.getRemotePath('remoteCfgPath')

        cmdRemote = remoteBinPath + "/kubectl delete -f " + remoteCfgPath + "/registry-pull-secret.yaml"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 9
0
    def deleteWeave(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')
        remotePluginPath = self.getRemotePath('remotePluginPath')

        cmdRemote = remoteBinPath + "/kubectl delete -f " + remotePluginPath + "/weave/weave.yaml"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 10
0
    def installMetricsServer(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        metricsConfigPath = self.getLocalPath('metricsConfigPath')
        # kbsPluginPath = self.getLocalPath('kbsPluginPath')
        # tmpPath = self.getLocalPath('tmpPath')

        remoteBinPath = self.getRemotePath('remoteBinPath')
        remotePluginPath = self.getRemotePath('remotePluginPath')

        # metricsConfigPath = kbsPluginPath + "/metrics-server"

        robj_admin.upload(
            metricsConfigPath + "/aggregated-metrics-reader.yaml",
            remotePluginPath + "/metrics/", True)
        robj_admin.upload(metricsConfigPath + "/auth-delegator.yaml",
                          remotePluginPath + "/metrics/", True)
        robj_admin.upload(metricsConfigPath + "/auth-reader.yaml",
                          remotePluginPath + "/metrics/", True)
        robj_admin.upload(metricsConfigPath + "/metrics-apiservice.yaml",
                          remotePluginPath + "/metrics/", True)
        robj_admin.upload(
            metricsConfigPath + "/metrics-server-deployment.yaml",
            remotePluginPath + "/metrics/", True)
        robj_admin.upload(metricsConfigPath + "/metrics-server-service.yaml",
                          remotePluginPath + "/metrics/", True)
        robj_admin.upload(metricsConfigPath + "/resource-reader.yaml",
                          remotePluginPath + "/metrics/", True)
        robj_admin.upload(metricsConfigPath + "/metrics-server-ingress.yaml",
                          remotePluginPath + "/metrics/", True)

        # robj_admin.upload(metricsConfigPath+"/auth-delegator.yaml", remotePluginPath+"/metrics/", True)
        # robj_admin.upload(metricsConfigPath+"/auth-reader.yaml", remotePluginPath+"/metrics/", True)
        # robj_admin.upload(metricsConfigPath+"/metrics-apiservice.yaml", remotePluginPath+"/metrics/", True)
        # robj_admin.upload(metricsConfigPath+"/metrics-server-service.yaml", remotePluginPath+"/metrics/", True)
        # robj_admin.upload(metricsConfigPath+"/resource-reader.yaml", remotePluginPath+"/metrics/", True)

        # file_config = metricsConfigPath + "/metrics-server-deployment.yaml"
        # file_tmp = tmpPath + "/metrics-server-deployment.yaml"
        # s1 = "k8s.gcr.io/metrics-server-amd64:v0.3.1".replace("/", "\/")
        # r1 = "registry.cn-beijing.aliyuncs.com/kube-systems/metrics-server:0.3.1".replace("/", "\/")
        # s2 = "k8s.gcr.io/addon-resizer:1.8.4".replace("/", "\/")
        # r2 = "registry.cn-beijing.aliyuncs.com/kube-systems/addon-resizer:1.8.4".replace("/", "\/")
        # sedRegex = "sed \"s/"+s1+"/"+r1+"/g\""
        # sedRegex = sedRegex + " | sed \"s/"+s2+"/"+r2+"/g\""
        # cmd_local = "cat %s | %s > %s" % (file_config, sedRegex, file_tmp)
        # robj_admin.local(cmd_local)
        # # 上传文件到远程主机
        # robj_admin.upload(file_tmp, remotePluginPath+"/metrics/", True)

        cmdRemote = remoteBinPath + "/kubectl create -f "
        cmdRemote = cmdRemote + remotePluginPath + "/metrics/"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 11
0
    def deleteDashboard(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')
        remotePluginPath = self.getRemotePath('remotePluginPath')

        cmdRemote = remoteBinPath + "/kubectl delete -f "
        cmdRemote = cmdRemote + remotePluginPath + "/dashboard/kubernetes-dashboard.yaml"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 12
0
    def deleteMetricsServer(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')
        remotePluginPath = self.getRemotePath('remotePluginPath')

        cmdRemote = remoteBinPath + "/kubectl delete -f "
        cmdRemote = cmdRemote + remotePluginPath + "/metrics/"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 13
0
    def deleteNginx(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')

        cmdRemote = remoteBinPath + "/kubectl delete deployment nginx"
        robj_admin.sudo(cmdRemote)

        cmdRemote = remoteBinPath + "/kubectl delete service nginx"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 14
0
    def deleteIngress(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remotePluginPath = self.getRemotePath('remotePluginPath')
        remoteBinPath = self.getRemotePath('remoteBinPath')

        #delete ingress
        print("delete ingress ...")
        cmdRemote = remoteBinPath + "/kubectl delete -f " + remotePluginPath + "/ingress/mandatory.yaml"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 15
0
    def validMetricsServer(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')

        #list pod and service
        cmdRemote = remoteBinPath + "/kubectl get pods -l k8s-app=metrics-server -n kube-system -o wide"
        robj_admin.sudo(cmdRemote)

        cmdRemote = remoteBinPath + "/kubectl get apiservice v1beta1.metrics.k8s.io -o yaml "
        robj_admin.sudo(cmdRemote)
Exemplo n.º 16
0
    def deleteDemoIngressHttps(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remotePluginPath = self.getRemotePath('remotePluginPath')
        remoteBinPath = self.getRemotePath('remoteBinPath')
        # remoteSslPath = self.getRemotePath('remoteSslPath')

        #delete ingress rules of https
        print("delete ingress rules of https ...")
        cmdRemote = remoteBinPath + "/kubectl delete -f "+remotePluginPath+"/ingress/nginx-ingress-rules-https.yaml"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 17
0
    def installDemoBusybox(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remotePluginPath = self.getRemotePath('remotePluginPath')
        remoteBinPath = self.getRemotePath('remoteBinPath')

        # tmpPath = self.getLocalPath('tmpPath')
        corednsConfigPath = self.getLocalPath('corednsConfigPath')

        #uninstall old service
        print("remove busybox container ...")
        cmdRemote = remoteBinPath + "/kubectl delete -f "+remotePluginPath+"/coredns/busybox.yaml"
        robj_admin.sudo(cmdRemote)

        #upload
        print("upload busybox yaml ...")
        robj_admin.upload(corednsConfigPath+"/busybox.yaml", remotePluginPath+"/coredns/")

        #install
        print("create busybox container ...")
        cmdRemote = remoteBinPath + "/kubectl create -f "+remotePluginPath+"/coredns/busybox.yaml"
        robj_admin.sudo(cmdRemote)

        print("sleep 5 seconds ...")
        robj_admin.sudo("sleep 5s")

        #view
        print("list pods of busybox ...")
        cmdRemote = remoteBinPath + "/kubectl get pods -o wide"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 18
0
    def validIngress(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')
        # remotePluginPath = self.getRemotePath('remotePluginPath')

        # corednsConfigPath = self.getLocalPath('corednsConfigPath')

        #get namespaces
        cmdRemote = remoteBinPath + "/kubectl get ns"
        robj_admin.sudo(cmdRemote)

        #get pod list in namespace ingress-nginx
        cmdRemote = remoteBinPath + "/kubectl get rs,pods,svc -n ingress-nginx -o wide"
        robj_admin.sudo(cmdRemote)

        #get pod list in namespace default
        cmdRemote = remoteBinPath + "/kubectl get rs,pods,svc -n default -o wide"
        robj_admin.sudo(cmdRemote)

        #get process list listenning on 80 and 443 on target node
        # cmdRemote = "netstat -tnlp | egrep \"80|443\""

        #test myapp service cluterip in deploy node
        #curl {clusterIp}

        #get ingress
        cmdRemote = remoteBinPath + "/kubectl get ingress"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 19
0
    def deleteDemoIngress(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')
        remotePluginPath = self.getRemotePath('remotePluginPath')

        # ingressConfigPath = self.getLocalPath('ingressConfigPath')

        # remove ingress rules
        cmdRemote = remoteBinPath + "/kubectl delete -f "+remotePluginPath+"/ingress/nginx-ingress-rules.yaml"
        robj_admin.sudo(cmdRemote)

        # remove ingress backend
        cmdRemote = remoteBinPath + "/kubectl delete -f "+remotePluginPath+"/ingress/nginx-ingress-backend.yaml"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 20
0
    def installCoredns(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remotePluginPath = self.getRemotePath('remotePluginPath')
        remoteBinPath = self.getRemotePath('remoteBinPath')

        tmpPath = self.getLocalPath('tmpPath')
        corednsConfigPath = self.getLocalPath('corednsConfigPath')

        #upload
        robj_admin.upload(corednsConfigPath + "/coredns-rbac.yaml",
                          remotePluginPath + "/coredns/", True)
        robj_admin.upload(corednsConfigPath + "/coredns-sa.yaml",
                          remotePluginPath + "/coredns/", True)
        robj_admin.upload(corednsConfigPath + "/coredns-configmap.yaml",
                          remotePluginPath + "/coredns/", True)
        robj_admin.upload(corednsConfigPath + "/coredns-deployment.yaml",
                          remotePluginPath + "/coredns/", True)

        ips_data = self.config_object.get_node_by_attr("name", "ips")
        serviceClusterDnsIp = ips_data.find('serviceClusterDnsIp').text

        sedRegex = "sed \"s/{serviceClusterDnsIp}/%s/g\"" % serviceClusterDnsIp

        file_tmp = tmpPath + "/coredns-service.yaml"
        file_config = corednsConfigPath + "/coredns-service.yaml"
        cmd_local = "cat %s | %s > %s" % (file_config, sedRegex, file_tmp)
        robj_admin.local(cmd_local)

        # 上传文件到远程主机
        robj_admin.upload(file_tmp, remotePluginPath + "/coredns/", True)

        #install
        cmdRemote = remoteBinPath + "/kubectl create -f " + remotePluginPath + "/coredns/coredns-rbac.yaml"
        robj_admin.sudo(cmdRemote)
        cmdRemote = remoteBinPath + "/kubectl create -f " + remotePluginPath + "/coredns/coredns-sa.yaml"
        robj_admin.sudo(cmdRemote)
        cmdRemote = remoteBinPath + "/kubectl create -f " + remotePluginPath + "/coredns/coredns-configmap.yaml"
        robj_admin.sudo(cmdRemote)
        cmdRemote = remoteBinPath + "/kubectl create -f " + remotePluginPath + "/coredns/coredns-deployment.yaml"
        robj_admin.sudo(cmdRemote)
        cmdRemote = remoteBinPath + "/kubectl create -f " + remotePluginPath + "/coredns/coredns-service.yaml"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 21
0
    def deleteDemoDockerPrivate(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        # docker_data = self.config_object.get_node_by_attr("name", "docker")
        # dockerUsername = docker_data.find('username').text
        # dockerPassword = docker_data.find('password').text
        # dockerDomain = docker_data.find('domain').text

        remoteBinPath = self.getRemotePath('remoteBinPath')
        remotePluginPath = self.getRemotePath('remotePluginPath')
        # dockerConfigPath = self.getLocalPath('dockerConfigPath')

        #uninstall old service
        cmdRemote = remoteBinPath + "/kubectl delete -f "+remotePluginPath+"/docker/busybox-demo.yaml"
        print(cmdRemote)
        robj_admin.sudo(cmdRemote)
Exemplo n.º 22
0
    def validDemoIngress(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        # remotePluginPath = self.getRemotePath('remotePluginPath')
        remoteBinPath = self.getRemotePath('remoteBinPath')
        # remoteSslPath = self.getRemotePath('remoteSslPath')

        # ingressConfigPath = self.getLocalPath('ingressConfigPath')

        #get ingress
        cmdRemote = remoteBinPath + "/kubectl get ingress"
        robj_admin.sudo(cmdRemote)

        #describe inress
        cmdRemote = remoteBinPath + "/kubectl describe ingress simple-fanout-example"
        robj_admin.sudo(cmdRemote) 
Exemplo n.º 23
0
    def validKbsMaster(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')

        # 在远端主机执行命令
        print("show apiserver info in port 6443: ")
        cmdRemote = "curl -L --cacert /opt/kubernetes/ssl/ca.pem"
        cmdRemote = cmdRemote + " https://" + self.proxy_host + ":" + self.proxy_port + "/api"
        robj_admin.sudo(cmdRemote)

        # print("show apiserver info in port 8080: ")
        # cmdValid="curl -L http://"+proxy_host+":8080/api"
        # robj_admin.sudo(cmdValid)

        print("show cluster info by kubectl: ")
        cmdValid = remoteBinPath + "/kubectl get cs"
        robj_admin.sudo(cmdValid)
Exemplo n.º 24
0
    def installNginx(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')

        #uninstall old nginx pod and service
        # cmdRemote = remoteBinPath + "/kubectl delete -f "+remoteDemoPath+"/nginx-demo-deployment.yaml"
        # robj_master1.sudo(cmdRemote)

        #upload nginx-demo-deployment.yaml to master
        # robj_master1.upload(kbsConfigPath+"/nginx-demo-deployment.yaml", remoteDemoPath+"/")

        # create pod
        # cmdRemote = remoteBinPath + "/kubectl apply -f "+remoteDemoPath+"/nginx-demo-deployment.yaml"
        # robj_master1.sudo(cmdRemote)

        cmdRemote = remoteBinPath + "/kubectl run nginx --image=nginx --replicas=3"
        robj_admin.sudo(cmdRemote)

        cmdRemote = remoteBinPath + "/kubectl expose deployment nginx --port=88 --target-port=80 --type=NodePort"
        robj_admin.sudo(cmdRemote)

        # list pod and service
        cmdRemote = remoteBinPath + "/kubectl get pod,svc -o wide"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 25
0
    def installCniNodeNormal(self, nodename):
        node_env = self.getEnv(nodename)
        # 初始化远程工具对象
        robj_node = Remote(node_env)

        cniBinPath = self.getLocalPath('cniBinPath')
        cniConfigPath = self.getLocalPath('cniConfigPath')
        kbsConfigPath = self.getLocalPath('kbsConfigPath')
        tmpPath = self.getLocalPath('tmpPath')
        remoteCniBinPath = self.getRemotePath('remoteCniBinPath')
        remoteCniCfgPath = self.getRemotePath('remoteCniCfgPath')
        remoteCfgPath = self.getRemotePath('remoteCfgPath')

        #stop relative service if the service is running
        cmdRemote = "systemctl stop kube-kubelet"
        robj_node.sudo(cmdRemote)

        # upload cni files
        robj_node.upload(cniBinPath + "/loopback", remoteCniBinPath + "/")
        robj_node.upload(cniBinPath + "/portmap", remoteCniBinPath + "/")
        robj_node.upload(cniConfigPath + "/99-loopback.conf",
                         remoteCniCfgPath + "/")

        #upload kubelet service config file for cni
        file_config = kbsConfigPath + "/kube-kubelet.conf"
        file_tmp = tmpPath + "/kube-kubelet.conf"
        plugin_name = "cni"
        sedRegex = "sed \"s/^--hostname-override={nodeName}/--hostname-override=%s/g\"" % node_env.host
        sedRegex = sedRegex + " | sed \"s/^--network-plugin={pluginName}/--network-plugin=%s/g\"" % plugin_name
        sedRegex = sedRegex + " | sed \"s/^--cni-conf-dir={confDir}/--cni-conf-dir=%s/g\"" % remoteCniCfgPath.replace(
            "/", "\/")
        sedRegex = sedRegex + " | sed \"s/^--cni-bin-dir={binDir}/--cni-bin-dir=%s/g\"" % remoteCniBinPath.replace(
            "/", "\/")
        cmd_local = "cat %s | %s > %s" % (file_config, sedRegex, file_tmp)
        print(cmd_local)
        robj_node.local(cmd_local)
        # 上传文件到远程主机
        robj_node.upload(file_tmp, remoteCfgPath + "/", True)

        print("systemd daemon reload ...")
        cmdRemote = "systemctl daemon-reload"
        robj_node.sudo(cmdRemote)

        print("restart kubelet service ...")
        cmdRemote = "systemctl restart kube-kubelet.service"
        robj_node.sudo(cmdRemote)

        print("check kubelet service ...")
        cmdRemote = "systemctl status kube-kubelet.service"
        robj_node.sudo(cmdRemote)
Exemplo n.º 26
0
    def installIngress(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remotePluginPath = self.getRemotePath('remotePluginPath')
        remoteBinPath = self.getRemotePath('remoteBinPath')

        # tmpPath = self.getLocalPath('tmpPath')
        ingressConfigPath = self.getLocalPath('ingressConfigPath')

        #remove
        cmdRemote = remoteBinPath + "/kubectl delete -f " + remotePluginPath + "/ingress/mandatory.yaml"
        robj_admin.sudo(cmdRemote)

        #upload yaml file
        robj_admin.upload(ingressConfigPath + "/mandatory.yaml",
                          remotePluginPath + "/ingress/", True)

        #install
        cmdRemote = remoteBinPath + "/kubectl apply -f " + remotePluginPath + "/ingress/mandatory.yaml"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 27
0
    def installDemoIngress(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remoteBinPath = self.getRemotePath('remoteBinPath')
        remotePluginPath = self.getRemotePath('remotePluginPath')

        ingressConfigPath = self.getLocalPath('ingressConfigPath')

        #upload ingress backend
        robj_admin.upload(ingressConfigPath+"/nginx-ingress-backend.yaml", remotePluginPath+"/ingress/", True)

        #install ingress backend
        cmdRemote = remoteBinPath + "/kubectl apply -f "+remotePluginPath+"/ingress/nginx-ingress-backend.yaml"
        robj_admin.sudo(cmdRemote)

        #upload ingress rules
        robj_admin.upload(ingressConfigPath+"/nginx-ingress-rules.yaml", remotePluginPath+"/ingress/", True)

        #install ingress rules
        cmdRemote = remoteBinPath + "/kubectl apply -f "+remotePluginPath+"/ingress/nginx-ingress-rules.yaml"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 28
0
    def deleteCoredns(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        remotePluginPath = self.getRemotePath('remotePluginPath')
        remoteBinPath = self.getRemotePath('remoteBinPath')

        # tmpPath = self.getLocalPath('tmpPath')
        # corednsConfigPath = self.getLocalPath('corednsConfigPath')

        #delete coredns resources
        cmdRemote = remoteBinPath + "/kubectl delete -f " + remotePluginPath + "/coredns/coredns-configmap.yaml"
        robj_admin.sudo(cmdRemote)

        cmdRemote = remoteBinPath + "/kubectl delete -f " + remotePluginPath + "/coredns/coredns-deployment.yaml"
        robj_admin.sudo(cmdRemote)
        cmdRemote = remoteBinPath + "/kubectl delete -f " + remotePluginPath + "/coredns/coredns-rbac.yaml"
        robj_admin.sudo(cmdRemote)
        cmdRemote = remoteBinPath + "/kubectl delete -f " + remotePluginPath + "/coredns/coredns-sa.yaml"
        robj_admin.sudo(cmdRemote)
        cmdRemote = remoteBinPath + "/kubectl delete -f " + remotePluginPath + "/coredns/coredns-service.yaml"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 29
0
    def installDemoDockerPrivate(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        docker_data = self.config_object.get_node_by_attr("name", "docker")
        dockerUsername = docker_data.find('username').text
        dockerPassword = docker_data.find('password').text
        dockerDomain = docker_data.find('domain').text

        remoteBinPath = self.getRemotePath('remoteBinPath')
        remotePluginPath = self.getRemotePath('remotePluginPath')
        dockerConfigPath = self.getLocalPath('dockerConfigPath')

        #get docker secret
        cmdRemote = remoteBinPath + "/kubectl get secret"
        robj_admin.sudo(cmdRemote)

        #valid
        busyboxAddress = "registry.cn-beijing.aliyuncs.com/ducafe/busybox"
        cmdLocal = "docker images | grep %s | awk '{print $3}'" % busyboxAddress
        robj_admin.local(cmdLocal)
        imageId = robj_admin.getResult().stdout.rstrip()
        # print(robj_admin.getResult().exited)

        if imageId == "":
            print("upload busybox image to aliyun repository ...")
            cmdLocal = "docker pull registry.cn-beijing.aliyuncs.com/ducafe/busybox:1.24"
            robj_admin.local(cmdLocal)
            cmdLocal = "docker images | grep %s | awk '{print $3}'" % busyboxAddress
            robj_admin.local(cmdLocal)
            imageId = robj_admin.getResult().stdout.rstrip()
            #login docker registry
            cmdLocal = "docker login --username=%s --password=%s %s" % (dockerUsername, dockerPassword, dockerDomain)
            robj_admin.local(cmdLocal)
            cmdLocal = "docker tag %s %s/kube-systems/busybox-demo:1.24" % (imageId, dockerDomain)
            robj_admin.local(cmdLocal)
            cmdLocal = "docker images"
            robj_admin.local(cmdLocal)
            cmdLocal = "docker push %s/kube-systems/busybox-demo:1.24" % dockerDomain
            robj_admin.local(cmdLocal)

        #upload
        robj_admin.upload(dockerConfigPath+"/busybox-demo.yaml", remotePluginPath+"/docker/")

        #install
        cmdRemote = remoteBinPath + "/kubectl create -f "+remotePluginPath+"/docker/busybox-demo.yaml"
        robj_admin.sudo(cmdRemote)

        cmdRemote = "sleep 2s"
        robj_admin.sudo(cmdRemote)
Exemplo n.º 30
0
    def installDockerPrivate(self):
        admin_env = self.getEnv("admin")
        # 初始化远程工具对象
        robj_admin = Remote(admin_env)

        docker_data = self.config_object.get_node_by_attr("name", "docker")
        dockerUsername = docker_data.find('username').text
        dockerPassword = docker_data.find('password').text
        dockerDomain = docker_data.find('domain').text

        tmpPath = self.getLocalPath('tmpPath')
        dockerConfigPath = self.getLocalPath('dockerConfigPath')
        remoteCfgPath = self.getRemotePath('remoteCfgPath')
        remoteBinPath = self.getRemotePath('remoteBinPath')

        #login docker registry
        cmdRemote = "docker login --username=%s --password=%s %s" % (
            dockerUsername, dockerPassword, dockerDomain)
        robj_admin.sudo(cmdRemote)

        #download docker login config file form master1 to local
        robj_admin.download("/root/.docker/config.json", tmpPath + "/")

        #view docker login config file content in local, and generate login credentials
        # dockerSecret = $(cat ./config.json | base64 -w 0)
        file_config = dockerConfigPath + "/registry-pull-secret.yaml"
        file_tmp = tmpPath + "/registry-pull-secret.yaml"
        with open(tmpPath + '/config.json') as file_object:
            contents = file_object.read()
            dockerSecret = base64.b64encode(
                contents.rstrip().encode("utf-8")).decode("utf-8")
            print("dockerSecret: " + dockerSecret)
            sedRegex = "s/{dockerSecret}/%s/g" % dockerSecret.replace(
                "/", r"\/")
            cmdLocal = "cat %s | sed \"%s\" > %s" % (file_config, sedRegex,
                                                     file_tmp)
            print(cmdLocal)
            robj_admin.local(cmdLocal)
            robj_admin.upload(file_tmp, remoteCfgPath + "/", True)

        #create docker secret pod
        cmdRemote = remoteBinPath + "/kubectl create -f " + remoteCfgPath + "/registry-pull-secret.yaml"
        robj_admin.sudo(cmdRemote)

        #get docker secret
        cmdRemote = remoteBinPath + "/kubectl get secret"
        robj_admin.sudo(cmdRemote)