예제 #1
0
  def _PostCreate(self):
    """Acquire cluster authentication."""
    cmd = util.GcloudCommand(
        self, 'container', 'clusters', 'get-credentials', self.name)
    env = self._GetRequiredGkeEnv()
    env['KUBECONFIG'] = FLAGS.kubeconfig
    cmd.IssueRetryable(env=env)

    if self.gpu_count:
      kubernetes_helper.CreateFromFile(NVIDIA_DRIVER_SETUP_DAEMON_SET_SCRIPT)
      kubernetes_helper.CreateFromFile(
          data.ResourcePath(NVIDIA_UNRESTRICTED_PERMISSIONS_DAEMON_SET))
    def _Create(self):
        run_cmd = [
            'run', self.name,
            '--image=%s' % self.image, '--port',
            str(self.port)
        ]

        limits = []
        if self.cpus:
            limits.append(f'cpu={int(1000 * self.cpus)}m')
        if self.memory:
            limits.append(f'memory={self.memory}Mi')
        if limits:
            run_cmd.append('--limits=' + ','.join(limits))

        if self.command:
            run_cmd.extend(['--command', '--'])
            run_cmd.extend(self.command)
        RunKubectlCommand(run_cmd)

        expose_cmd = [
            'expose', 'deployment', self.name, '--type', 'NodePort',
            '--target-port',
            str(self.port)
        ]
        RunKubectlCommand(expose_cmd)
        with vm_util.NamedTemporaryFile() as tf:
            tf.write(_K8S_INGRESS.format(service_name=self.name))
            tf.close()
            kubernetes_helper.CreateFromFile(tf.name)
예제 #3
0
  def _Create(self):
    run_cmd = [
        FLAGS.kubectl,
        'run',
        self.name,
        '--image=%s' % self.image,
        '--limits=cpu=%sm,memory=%sMi' % (int(1000 * self.cpus), self.memory),
        '--port', str(self.port)
    ]
    if self.command:
      run_cmd.extend(['--command', '--'])
      run_cmd.extend(self.command)
    vm_util.IssueCommand(run_cmd)

    expose_cmd = [
        FLAGS.kubectl,
        '--kubeconfig', FLAGS.kubeconfig,
        'expose', 'deployment', self.name,
        '--type', 'NodePort',
        '--target-port', str(self.port)
    ]
    vm_util.IssueCommand(expose_cmd)
    with vm_util.NamedTemporaryFile() as tf:
      tf.write(_K8S_INGRESS.format(service_name=self.name))
      tf.close()
      kubernetes_helper.CreateFromFile(tf.name)
예제 #4
0
    def _PostCreate(self):
        """Acquire cluster authentication."""
        super(GkeCluster, self)._PostCreate()
        cmd = util.GcloudCommand(self, 'container', 'clusters',
                                 'get-credentials', self.name)
        env = os.environ.copy()
        env['KUBECONFIG'] = FLAGS.kubeconfig
        cmd.IssueRetryable(env=env)

        if self.vm_config.gpu_count:
            kubernetes_helper.CreateFromFile(
                NVIDIA_DRIVER_SETUP_DAEMON_SET_SCRIPT)
            kubernetes_helper.CreateFromFile(
                data.ResourcePath(NVIDIA_UNRESTRICTED_PERMISSIONS_DAEMON_SET))

        # GKE does not wait for kube-dns by default
        logging.info('Waiting for kube-dns')
        self.WaitForResource('deployment/kube-dns',
                             condition_name='Available',
                             namespace='kube-system')
def CreateResource(resource_body):
    with vm_util.NamedTemporaryFile() as tf:
        tf.write(resource_body)
        tf.close()
        return kubernetes_helper.CreateFromFile(tf.name)