Access Rok from External Client

This guide contains instructions to access Rok in your Arrikto EKF deployment from an external client.

What You’ll Need

Choose one of the following options, depending on your desired environment.

Contact Arrikto

If you are using a custom image or environment, make sure it supports Python3 and contact the Arrikto Tech Team to provide you with the wheels to install the Rok client and CLI.

Contact Arrikto

If you are using a custom image or environment, make sure it supports Python3 and contact the Arrikto Tech Team to provide you with the wheels to install the Rok client and CLI.

Procedure

Choose one of the following options, depending on your desired environment.

  1. Select Snapshots from the left-side menu.

    ../../../_images/menu-snapshots.png
  2. Select the namespace you wish to view using the Kubeflow Dashboard namespace selector.

    ../../../_images/rok-namespace-selector.png
  1. Specify the namespace you wish to access:

    jovyan@mynotebook-0:~$ export ROK_ACCOUNT="<ACCOUNT>"

    Replace <ACCOUNT> with the namespace, for example:

    jovyan@mynotebook-0:~$ export ROK_ACCOUNT="kubeflow-user"

    Note

    Instead of specifying the namespace via an environment variable, you can alternatively include the --account command line argument during the invocation of the CLI.

  2. Specify the endpoint of your Kubernetes cluster:

    jovyan@mynotebook-0:~$ export CLUSTER_ENDPOINT="<CLUSTER_ENDPOINT>"

    Replace <CLUSTER_ENDPOINT> with the endpoint of your Kubernetes cluster:

    jovyan@mynotebook-0:~$ export CLUSTER_ENDPOINT="https://arrikto-cluster.apps.example.com"
  3. Specify the endpoint of your cluster’s Rok API:

    jovyan@mynotebook-0:~$ export ROK_URL="${CLUSTER_ENDPOINT?}/rok"

    Note

    Instead of specifying the Rok API endpoint via an environment variable, you can alternatively include the --url command line argument during the invocation of the CLI.

  4. Specify the endpoint of your cluster’s Kubernetes API:

    jovyan@mynotebook-0:~$ export KUBERNETES_SERVICE_HOST="${CLUSTER_ENDPOINT?}/kubernetes"

    Note

    Instead of specifying the Kubernetes API endpoint via an environment variable, you can alternatively include the --kubernetes-host command line argument during the invocation of the CLI.

  5. Specify the location of the file holding your service account token in your file system:

    jovyan@mynotebook-0:~$ export ROK_SA_TOKEN="file:<PATH_TO_TOKEN>"

    Replace <PATH_TO_TOKEN> with the file system path of the file containing your token, for example:

    jovyan@mynotebook-0:~$ export ROK_SA_TOKEN="file:/home/jovyan/kubeflow-user-rok-external.token"

    Note

    Instead of specifying the location of the token in the file system via an environment variable, you can alternatively include the --sa-token command line argument during the invocation of the CLI.

  6. Use the rok CLI to interact with the Rok API server:

    jovyan@mynotebook-0:~$ rok account-show Account Information Account Name kubeflow-user Account UUID 1790af25-41c2-4e37-92cb-a2a3ee11fb9a Bucket Count 5 Version Bytes Used 482GiB Version Count 190 Bytes Used 100GiB Object Count 16 Created At 2021-10-05T16:11:56.764930+00:00
    jovyan@mynotebook-0:~$ rok bucket-list Name Objects Object Bytes Versions Version Bytes Type Paused auto-backup 2 20GiB 12 40GiB local False
  1. Specify the location of the file holding your service account token in your file system:

    jovyan@mynotebook-0:~$ export ROK_SA_TOKEN="file:<PATH_TO_TOKEN>"

    Replace <PATH_TO_TOKEN> with the file system path of the file containing your token, for example:

    jovyan@mynotebook-0:~$ export ROK_SA_TOKEN="file:/home/jovyan/kubeflow-user-rok-external.token"
  2. Create a new Python file and name it access-rok.py:

    jovyan@mynotebook-0:~$ touch access-rok.py
  3. Copy and paste the following code inside access-rok.py:

    access-rok-external.py
    1# Copyright © 2022 Arrikto Inc. All Rights Reserved.
    2
    3"""Access the Rok API."""
    4-17
    4
    5from rok_gw_client import RokClient
    6
    7NAMESPACE = "mynamespace"
    8CLUSTER_ENDPOINT = "https://myendpoint.com"
    9
    10# Initialize the Rok client
    11URL = "%s/rok" % CLUSTER_ENDPOINT
    12KUBERNETES_HOST = "%s/kubernetes" % CLUSTER_ENDPOINT
    13client = RokClient(account=NAMESPACE, url=URL,
    14 kubernetes_host=KUBERNETES_HOST)
    15
    16
    17# Access the Rok API
    18account_info, buckets = client.bucket_list()
    19print("Successfully retrieved %d Rok bucket(s) in namespace '%s'"
    20 % (len(buckets), NAMESPACE))

    Alternatively, download the Python file above in your execution environment.

  4. Update the following fields in the file:

    1. Set NAMESPACE to the Kubernetes namespace you wish to access.

    2. Set CLUSTER_ENDPOINT to the endpoint of your Kubernetes cluster.

      access-rok-external-updated.py
      1# Copyright © 2022 Arrikto Inc. All Rights Reserved.
      2
      3"""Access the Rok API."""
      4
      5from rok_gw_client import RokClient
      6
      7-NAMESPACE = "mynamespace"
      8-CLUSTER_ENDPOINT = "https://myendpoint.com"
      9+NAMESPACE = "kubeflow-user"
      10+CLUSTER_ENDPOINT = "https://arrikto-cluster.apps.example.com"
      11
      12# Initialize the Rok client
      13URL = "%s/rok" % CLUSTER_ENDPOINT
      14-19
      14KUBERNETES_HOST = "%s/kubernetes" % CLUSTER_ENDPOINT
      15client = RokClient(account=NAMESPACE, url=URL,
      16 kubernetes_host=KUBERNETES_HOST)
      17
      18
      19# Access the Rok API
      20account_info, buckets = client.bucket_list()
      21print("Successfully retrieved %d Rok bucket(s) in namespace '%s'"
      22 % (len(buckets), NAMESPACE))
  5. Run the script using Python 3:

    jovyan@mynotebook-0:~$ python3 access-rok.py Successfully retrieved 3 Rok bucket(s) in namespace 'kubeflow-user'

Summary

You have successfully accessed Rok using an external client.

What’s Next

Check out the rest of the user guides regarding Rok.