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
-
Clone the
egs-sdk.git
repository using the following command:git clone https://github.com/kubeslice-ent/egs-sdk.git
-
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"
Workspace Parameters
Parameter | Description |
---|---|
projectname | The project name associated with the workspaces. |
workspaces | A list of workspace configurations. |
name | The name of the workspace. |
namespaces | List of namespaces associated with the workspace. |
clusters | List of clusters to associate with the workspace |
username | The username associated with the workspace. |
The contact email for the workspace. |
Run the Script
-
Go to the examples01 folder.
-
Use the
create_workspace.py
script from the examples01 folder. -
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
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 authentication token as
token.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