Beispiel #1
0
    def deploy_kubernetes_cluster(self):
        configurator = docker_configurator(self.hosts)
        configurator.config_docker()

        self._install_kubeadm()
        if self.kube_master is None:
            self.kube_master = self.hosts[0]
            kube_workers = self.hosts[1:]
        else:
            kube_workers = [host for host in self.hosts if host != self.kube_master]

        logger.info('Initializing kubeadm on master')
        cmd = 'kubeadm init --pod-network-cidr=10.244.0.0/16'
        execute_cmd(cmd, [self.kube_master])

        cmd = '''mkdir -p $HOME/.kube
                 cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
                 chown $(id -u):$(id -g) $HOME/.kube/config'''
        execute_cmd(cmd, [self.kube_master])

        cmd = 'kubectl apply -f https://github.com/coreos/flannel/raw/master/Documentation/kube-flannel.yml'
        execute_cmd(cmd, [self.kube_master])

        cmd = 'kubeadm token create --print-join-command'
        _, result = execute_cmd(cmd, [self.kube_master])

        logger.debug('Adding %s kube workers' % len(kube_workers))
        cmd = 'kubeadm join' + \
            result.processes[0].stdout.split('kubeadm join')[-1]
        execute_cmd(cmd.strip(), kube_workers)

        logger.info('Deploying Kubernetes cluster successfully')
        logger.info('Kubernetes master: %s' % self.kube_master)

        return self.kube_master, kube_workers
Beispiel #2
0
    def deploy_docker_swarm_cluster(self):
        configurator = docker_configurator(self.hosts)
        configurator.config_docker()

        if self.ds_manager is None:
            self.ds_manager = self.hosts[0]
            ds_workers = self.hosts[1:]
        else:
            ds_workers = [host for host in self.hosts if host != self.ds_manager]

        logger.info('Getting IP of docker swarm manager')
        cmd = "hostname -I"
        _, r = execute_cmd(cmd, [self.ds_manager])
        ds_manager_ip = r.processes[0].stdout.strip().split(' ')[0]

        logger.info('Creating a new swarm')
        cmd = 'docker swarm init --advertise-addr %s' % ds_manager_ip
        execute_cmd(cmd, [self.ds_manager])

        logger.info('Joining all docker swarm worker')
        cmd = 'docker swarm join-token worker | grep "docker swarm join"'
        _, r = execute_cmd(cmd, [self.ds_manager])

        cmd = r.processes[0].stdout.strip()
        execute_cmd(cmd, ds_workers)

        logger.info('Finish deploying docker swarm cluster')
        logger.info('Docker swarm manager: %s (%s)' % (self.ds_manager, ds_manager_ip))

        return self.ds_manager, ds_workers
    def deploy_kubernetes_cluster(self):
        configurator = docker_configurator(self.hosts)
        configurator.config_docker()

        self._install_kubeadm()
        if self.kube_master is None:
            self.kube_master = self.hosts[0]
            kube_workers = self.hosts[1:]
        else:
            kube_workers = [
                host for host in self.hosts if host != self.kube_master
            ]
        logger.info('Kubernetes master: %s' % self.kube_master)
        logger.info(
            'Changing cgroups driver of Docker to systemd to be compatible with kubeadm v1.22+'
        )
        # https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/configure-cgroup-driver/
        cmd = '''cat <<EOF >> /etc/docker/daemon.json
        {
        "exec-opts": ["native.cgroupdriver=systemd"]
        }
        EOF'''
        execute_cmd(cmd, self.hosts)

        logger.info('Restarting Docker')
        cmd = 'systemctl restart docker'
        execute_cmd(cmd, self.hosts)

        logger.info('Initializing kubeadm on master')
        cmd = 'kubeadm init --pod-network-cidr=10.244.0.0/16'
        execute_cmd(cmd, [self.kube_master])

        cmd = '''mkdir -p $HOME/.kube
                 cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
                 chown $(id -u):$(id -g) $HOME/.kube/config'''
        execute_cmd(cmd, [self.kube_master])

        cmd = 'kubectl apply -f https://github.com/coreos/flannel/raw/master/Documentation/kube-flannel.yml'
        execute_cmd(cmd, [self.kube_master])

        cmd = 'kubeadm token create --print-join-command'
        _, result = execute_cmd(cmd, [self.kube_master])

        logger.debug('Adding %s kube workers' % len(kube_workers))
        cmd = 'kubeadm join' + \
            result.processes[0].stdout.split('kubeadm join')[-1]
        execute_cmd(cmd.strip(), kube_workers)

        logger.debug('Adding kubectl completion bash on master')
        cmd = '''echo 'source <(kubectl completion bash)' >> ~/.bashrc
                 kubectl completion bash >/etc/bash_completion.d/kubectl
                 source ~/.bashrc'''
        execute_cmd(cmd, [self.kube_master])

        logger.info('Deploying Kubernetes cluster successfully')

        return self.kube_master, kube_workers
Beispiel #4
0
    def config_host(self, hosts):
        logger.info("Starting configure AntidoteDB on nodes")
        logger.debug("Init configurator: docker_configurator")
        configurator = docker_configurator(hosts)
        configurator.config_docker()

        logger.info("Pull AntidoteDB docker image")
        cmd = 'docker pull antidotedb/antidote'
        execute_cmd(cmd, hosts)

        logger.info("Run AntidoteDB container")
        cmd = 'docker run -d --name antidote -p "8087:8087" antidotedb/antidote'
        execute_cmd(cmd, hosts)
        logger.info("Finish configuring AntidoteDB on all hosts")
Beispiel #5
0
    def config_host(self, hosts):
        logger.info("Starting configuring Kubernetes cluster")
        logger.info("Init configurator: docker_configurator")
        configurator = docker_configurator(hosts)
        configurator.config_docker()

        logger.info("Init configurator: kubernetes_configurator")
        configurator = kubernetes_configurator(hosts)
        kube_master, kube_workers = configurator.deploy_kubernetes_cluster()
        logger.info('Kubernetes workers: %s' % kube_workers)

        self._get_credential(kube_master=kube_master)

        logger.info("Finish configuring Kubernetes cluster")
    def setup_env(self):
        """Setting the experiment environment base on the user's requirements

        This function normally contains two steps:
            1. Provisioning hosts on G5k if needed
               (if you provided the OAR_JOB_ID of the already reserved hosts,
               the provisioner will not make a reservation again)
            2. Configuring all your necessary packages/services on those hosts.
        """
        provisioner = g5k_provisioner(
            config_file_path=self.args.config_file_path,
            keep_alive=self.args.keep_alive,
            out_of_chart=self.args.out_of_chart,
            oar_job_ids=self.args.oar_job_ids,
            no_deploy_os=self.args.no_deploy_os,
            is_reservation=self.args.is_reservation,
            job_name="cloudal")
        provisioner.provisioning()
        self.hosts = provisioner.hosts
        oar_job_ids = provisioner.oar_result
        self.oar_result = provisioner.oar_result

        ##################################################
        #  Configuring hosts with your applications here #
        ##################################################

        # For example: install some dependencies
        configurator = packages_configurator()
        configurator.install_packages(['sysstat', 'htop'], self.hosts)

        # or call the provided configurator (by cloudal) to deploy some well-known services
        configurator = docker_configurator(self.hosts)
        configurator.config_docker()

        # or perform some commands on all of hosts
        logger.info("Downloading cloudal")
        cmd = "cd /tmp/ && git clone https://github.com/ntlinh16/cloudal.git"
        execute_cmd(cmd, self.hosts)

        return oar_job_ids
 def config_host(self, hosts):
     logger.info("Init configurator: docker_configurator")
     configurator = docker_configurator(hosts)
     configurator.config_docker()
Beispiel #8
0
 def config_host(self):
     logger.debug("Init configurator")
     configurator = docker_configurator(self.hosts)
     configurator.config_docker()