Skip to main content
Version: 1.12.0

Workspaces

As an admin, a typical activity may be to create a new workspace for a team, to obtain a KubeConfig file that allows that team to access a namespace in the workspace, and an API key to allow the team to issue EGS SDK commands and log in to the EGS UI.

This example shows how one can automate the creation of these resources.

Prerequisites

Before running the script, ensure the following requirements are met:

Install Python SDK

Use the following command to install the required Python SDK:

pip install git+https://github.com/kubeslice-ent/egs-sdk.git

If you want to install a specific branch or version, specify the branch as shown in the following command:

pip install git+https://github.com/kubeslice-ent/egs-sdk.git@<branch_or_tag_name>

Locate the Examples Directory

  1. Clone the egs-sdk.git repository using the following command:

    git clone https://github.com/kubeslice-ent/egs-sdk.git
  2. Go to the examples directory using the following command:

    cd egs-sdk/examples/examples01

KubeConfig Setup

The KubeConfig for the target cluster must be configured before running this script.

Set Environment Variables

Ensure the following environment variables are set:

export EGS_ENDPOINT=<your-egs-endpoint>
export EGS_API_KEY=<your-egs-api-key>

Python

Ensure you have Python version 3.9 or later installed on your system.


Workspace Configuration YAML

The script uses a configuration file in YAML format. The following is an example YAML.

projectname: "avesha"
workspaces:
- name: "workspace-b"
namespaces:
- "namespace-b2"
- "namespace-b1"
clusters:
- "worker-1"
# - "worker-2" (Optional additional cluster)
username: "admin-1"
email: "admin1@acme.io"
apiKeyValidity: "2025-12-31"

Workspace Parameters

ParameterDescription
projectnameThe project name associated with the workspaces.
workspacesA list of workspace configurations.
nameThe name of the workspace.
namespacesList of namespaces associated with the workspace.
clustersList of clusters to associate with the workspace
usernameThe username associated with the workspace.
emailThe contact email for the workspace.
apiKeyValidityThe validity of the API Key, which is used to authenticate and authorize access to an API.

Run the Script

  1. Go to the examples01 folder.

  2. Use the create_workspace.py script from the examples01 folder.

  3. To create workspaces based on the configuration file, use the following command:

    python create_workspace.py --config workspace_config.yaml

Script Capability

This script:

  • Authenticates with the EGS API using provided environment variables
  • Reads the workspace configuration YAML file
  • Creates workspaces based on the configuration
  • Retrieves and saves the KubeConfig for each cluster under the corresponding workspace folder
  • Fetches the authentication token from the Kubernetes secret and saves it as token.txt under the workspace folder
info

There are other example scripts available in the examples folder. Try them out to create and delete workspaces.

Output

On a successful execution, the script:

  • Creates workspaces and saves kubeconfig files in kubeconfigs/<workspace_name>/
  • Retrieves and saves the Kubernetes API Key in apikey.txt.
  • Logs messages indicating success or failure for each step

Troubleshooting

If you encounter issues, then:

  • Ensure that the KubeConfig file for your cluster is correctly set up
  • Verify that the correct EGS API credentials are being used
  • Check for proper formatting of the YAML configuration file
  • Review error messages to identify missing dependencies or incorrect configurations