====================
Gravity Installation
====================

`Gravity <https://goteleport.com/gravity/docs/>`_ is an open-source, containerized Kubernetes framework that allows containerized applications like Anaconda Enterprised to be delivered in a self-contained installer that includes a special containerized implementation of Kubernetes. Anaconda has shipped Data Science & AI Workbench in a Gravity package since its first release.

.. caution:: 

    Due to changes in the business model of `Teleport <https://goteleport.com/>`_, the original developers of Gravity, Anaconda is limiting the use of Gravity-based installers to existing customers and :doc:`plans to end support for Gravity entirely at some point in the future <../reference/gravity-support>`. Existing Gravity customers are strongly encouraged to migrate their cluster to our new K3s implementation as soon as possible. Anaconda has developed a special process that allows you to migrate from Gravity to K3s without losing any of your existing data!

After you have verified that your :doc:`environment is prepared for installation <../environment-prep/gravity-prep>` by completing the :ref:`pre-installation checklist <grav_checklist>`, you're ready to install the cluster!

   .. note:: 

      The Gravity installation process only sets up a single control plane node. Once installation is complete, you can :doc:`add additional nodes <../admin/resources/gravity/add-remove-node>` as desired, including GPUs.

#. Open a terminal on the master node and log in to a service account with sudo access. 
#. Download the installer by running the following command:

   .. code-block:: none

      # Replace <INSTALLER_LOCATION> with the provided location of the installer
      curl -O <INSTALLER_LOCATION>

   .. note:: 

      If you are in an air-gapped environment, you must deliver the installer to the master node in an alternate manner. 

#. Decompress the installer and enter the top directory by running the following commands:

   .. code-block:: none

      # Replace <INSTALLER> with the installer file you just downloaded
      tar xzvf <INSTALLER>
      cd <INSTALLER>

#. Set up and initialize your conda environment by running the following command:

   .. code-block:: none
     
      ./conda-bootstrap.sh

#. Enter ``yes`` to allow the installer to initialize your ``ae5-conda`` environment by running ``conda init`` when prompted. 

#. Verify your environment successfully created by running the following command:

   .. code-block:: none

      conda env list
  
   .. note:: 
      
      This command returns a list of existing conda environments. You should see a ``base`` environment present with an asterisk beside the directory to indicate it is currently active.

#. Perform the Anaconda preflight system check on the master node by running the following command:

   .. code-block:: none
     
      ae-preflight

   .. note::

      You will receive an overall ``PASS`` or ``WARN`` result from the script. The output is captured in a ``results.txt`` file for later reference, if necessary. If something goes wrong, you can view the results to determine the issue and correct it.  

#. Create a file named ``values.yaml`` and populate it with the following content:

   .. code-block:: none

     # Replace <HOSTNAME> with the fully qualified domain name of the host server
     # Replace <GID> with the group ID with read-write access to the shared network file system (NFS) volume
     # Replace <SERVER_FQDN> with the address of the shared NFS volume
     # Replace <SERVER_PATH> with the path to the shared NFS volume     
     apiVersion: v1
     kind: ConfigMap
     metadata:
       name: anaconda-enterprise-install
     data:
       values: |
         hostname: <HOSTNAME>
         persistence: 
           groupID: <GID>
           nfs:
             server: <SERVER_FQDN>
             path: <SERVER_PATH>

   If you are installing a single-node cluster and you want to use the ``/opt/anaconda/storage`` volume for managed persistence, the ``persistence:`` section of the ``values.yaml`` can be entered as:

      .. code-block:: none

            persistence: 
               pvc: anaconda-storage

      .. note::

         The direct use of ``/opt/anaconda/storage`` for managed persistence works *only* for single-node clusters. It must be replaced with a network file system (NFS) configuration *before* adding additional nodes to the cluster. Otherwise, sessions and deployments launched on the additional nodes will fail to start. For more information, see :ref:`managed persistence <managed_persistence>`. 

#. Run the gravity installation command:

   .. code-block:: none

      # Replace <ADVERTISE-ADDR> with the IP address you want to be visible to the other nodes. If you have a private network and all nodes can communicate on it, use the private IP address for the advertise address
      # Replace <CLUSTERNAME> with the name you're giving to your cluster. Alphanumeric characters and periods only
      # Replace <VALUES_PATH> with the filepath to the values.yaml file you just created
      sudo ./gravity install --advertise-addr=<ADVERTISE-ADDR> --cluster=<CLUSTERNAME> --config <VALUES_PATH> --service-uid=$(id -u) --cloud-provider=generic

   Here is an example of what the installation command looks like for a single-node cluster:

   .. code-block:: none 

      sudo ./gravity install --advertise-addr=192.168.1.1 --cluster=MyCluster --config ./values.yaml --service-uid=$(id -u) --cloud-provider=generic

   If you are using an alternate ``TMPDIR``, prepend the command with this new value. For example:

   .. code-block:: none 

      sudo TMPDIR=/mytmp ./gravity install --advertise-addr=192.168.1.1 --cluster=MyCluster --config=./values.yaml --service-uid=$(id -u) --cloud-provider=generic

   .. caution:: 

      The ``--service-uid`` is the service account UID and cannot be a root user. If you are performing a reinstallation of Workbench, you must delete the previous ``planet`` user prior to setting the new ``--service-uid``.

.. _complete_upgrade_install:

10. Monitor the progress from the command line. Your output will look like this:

      .. code-block:: none

         * [0/100] starting installer
         * [0/100] preparing for installation... please wait
         * [0/100] application: AnacondaEnterprise:5.5.x
         * [0/100] starting non-interactive install
         * [0/100] initializing the operation
         * [20/100] configuring packages
         * [50/100] installing software

#. Allow time for the process to complete (approximately 20-30 minutes).

#. Create a local user account and password to log in to the Gravity Operations Center. To do so, enter the Gravity environment from any of the nodes by running the following command:

   .. code-block:: none

      sudo gravity enter

#. Create a local user account and password by running the following command:
   
   .. code-block:: none

      # Replace <EMAIL> with the email address for the account
      # Replace <PASSWORD> with a password for the account. The password must be six characters long
      gravity --insecure user create --type=admin --email=<EMAIL> --password=<PASSWORD> --ops-url=https://gravity-site.kube-system.svc.cluster.local:3009

#. Inform gravity that you have completed the installation by running the following command from within the Gravity environment: 

   .. code-block:: none

      gravity site complete

#. Open a web browser and navigate to your instance of Workbench. 
   
   .. note:: 
      
      Your browser may initially refuse to connect due to the use of our generated, self-signed SSL certificates. You should temporarily permit your browser to proceed anyway. You will also have to do the same every time you start a new session or deployment, so it is best to complete the next step as soon as possible.

#. :doc:`Update your SSL cerfiticates <certs>`.

#. Proceed to the :doc:`post-install configuration steps <config>`.
