Implementing Team Workspaces
#
What are Team Workspaces?A workspace is a GitOps repository tied to one or more namespaces in a WKP cluster and a set of Kubernetes controllers that are keeping them in sync. All Kubernetes objects created in the workspace repository are applied to the specified namespace(s) by the controllers. One can create a workspace by adding a Workspace custom resource manifest in the cluster repository.
#
How to: Enable the team workspaces featureTo enable the team workspaces feature edit the setup/config.yaml
file, set the enabledFeatures: teamWorkspaces
field to true
, commit and push to the cluster repository.
After a few seconds, the team workspaces components are deployed in the wkp-workspaces
namespace.
#
How To: Create and use a team workspaceThe team workspaces feature supports the creation of repositories in either GitHub or GitLab. It also supports self-hosted instances of the above.
New team workspace repositories will be created in an organization. A personal access token is therefore needed for the succesful creation of the workspace repository and the setup of its deploy keys.
#
Using a GitHub tokenChoose a user that is a member of your organization. Using the GitHub UI, create a personal access token for this user that has
repo
andadmin:org
permissions and store it in an environment variable i.e.Run the following command to generate a sealed secret manifest for the token:
The
--secret-name
parameter indicates the name of the secret that will be created in the cluster. The name of the secret needs to be unique as there can be more than one git providers used at any given point.For self-hosted instances, you need to also specify the
--hostname
parameter:If this parameter is not specified, the
--hostname
parameter will default togithub.com
After running this command, a new manifest containing a sealed secret for the git provider token should be generated in the./cluster/platform/workspaces
directory.Push the sealed secret to the config repository, so that flux can apply it:
This step can be skipped if the
--git-commit-push
parameter is present in the previous step.
#
Using a GitLab tokenChoose a user that is a member of your organization. Using the GitLab UI, create a personal access token for this user that has the
api
permission and store it in an environment variable i.e.Run the following command to generate a sealed secret manifest for the token:
The
--secret-name
parameter indicates the name of the secret that will be created in the cluster. The name of the secret needs to be unique as there can be more than one git providers used at any given point.For self-hosted instances, you need to also specify the
--hostname
parameter:If this parameter is not specified, the
--hostname
parameter will default togitlab.com
After running this command, a new manifest containing a sealed secret for the git provider token should be generated in the./cluster/platform/workspaces
directory.Push the sealed secret to the config repository, so that flux can apply it:
This step can be skipped if the
--git-commit-push
parameter is present in the previous step.
#
Adding a token manuallyThe wk workspaces add-provider
command is a convenient way to add a provider token to the cluster. It is also possible to add a token manually which can be useful in cases where a solution like SOPS or Vault is used to store secrets.
For example, the following command will generate a sealed secret manifest for the token:
However, the generated secret will need some additional metadata in order for it to be used by other parts of the WKP platform. In those cases where a git provider token needs to be created manually, please ensure the following label and annotations are in place for the secret:
Label:
wkp.weave.works/type: git-provider-token
Annotations:
wkp.weave.works/git-provider-type: github
or wkp.weave.works/git-provider-type: gitlab
depending on the git provider used.
wkp.weave.works/git-provider-hostname: github.com
or wkp.weave.works/git-provider-hostname: gitlab.com
depending on the git provider used.
If a self-hosted instance is used then the wkp.weave.works/git-provider-hostname
annotation needs to point to the hostname of that instance i.e. wkp.weave.works/git-provider-hostname: git.wkp.weave.works
You can use kubectl
to create the above after the secret has been created:
#
Creating a WorkspaceOnce the secret is deployed to the cluster, you can start creating team workspaces:
Create a Workspace manifest:
Commit the manifest to the
cluster/manifests
directory in the config repository.Wait until the
wkp-workspaces-controller
creates the namespace(s). This shouldn't take longer than the sync interval specified in the manifest plus a few seconds.- Note: for troubleshooting, check the
wkp-workspaces-controller
logs (for applying failures) andsource-controller
logs (for GitHub API errors)
- Note: for troubleshooting, check the
Commit something to the newly created workspace repository (accessible by the workspace link in the UI). The controllers will reconcile your changes with the workspace namespace(s).
#
Workspace CRD fieldsThe Workspace manifest defines three sections in its spec:
gitProvider
: The git provider which should host the git repository of the workspace and an access token for operating on the repo. Both GitHub and GitLab are supported.gitRepository
: The repository details, which teams should get access to the workspace. The team needs to exist in the provider. The branch and path, if specified, restrict the locations that will be examined for workloads that need to be deployed. Only manifests checked in on the specified branch within the specified repository directory will be processed; "branch" defaults to "main" and "path" defaults to "./".clusterScope
:- the list of namespaces that are in the workspace.
For each of the namespaces, additional options may be defined:
resourceQuota
: used to define constraints that limit aggregate resource consumption in the namespacelimitRange
: used to define a policy to constrain resource allocations for pods or containers running in the namespace
- the role of the members of the workspace with possible options:
workspace-member
: members get limited permissions on the target namespacesnamespace-admin
: members get admin permissions on the target namespacescluster-admin
: members get cluster admin permissions
- a network policy for the namespaces with possible option:
workspace-isolation
: services created in the target namespaces cannot be accessed from namespaces outside of the workspace, and vice versa services running in namespaces outside of the workspace, cannot be accessed from within the namespace. If this field is not included in the manifest no network policy will be applied.
- the list of namespaces that are in the workspace.
For each of the namespaces, additional options may be defined:
#
Cluster access for workspace teamsAfter creating a workspace the teams specified in the gitRepository
section will have access to the repository. These teams can manage the workspace by adding and removing manifests, committing and pushing.
It is also very useful for these teams to have kubectl
access to the workspace to view logs and deployment statuses. Limited access to only those namespaces managed by the workspace is provided by a service account automatically generated during the creation process. To generate a kubeconfig file that uses this service account run:
This will write the config to standard output and can be manually forwarded to the workspace teams. The teams can then save it to a file demo-workspace-kubeconfig
use it like so:
The kubeconfig file sets the default namespace to the first namespace listed in the Workspace definition. In this case the above command will show the pods in demo-app
. To interact with other workspace namespaces (like demo-db
in this case), the usual kubectl namespace flag can be provided: kubectl --kubeconfig=demo-workspace-kubeconfig --namespace=demo-db get pods
If the cluster goes through a Kubernetes version upgrade, kubeconfig files will need to be regenerated.
#
Updating a workspaceAfter a workspace has been created, it is possible to change multiple of its fields. The modifiable fields of the workspace CRD consist of:
in the spec
map:
- the
interval
of the reconciliation - the
suspend
field, toggling the reconciliation on or off
in the clusterScope
map:
namespaces
can be removed or added to the workspace. A namespace can only be in one workspace. If the namespace doesn't exist it will be created. When a namespace is removed from a workspace, the members of the workspace will not be able to access it anymore, and deployments will not be reconciled from the workspace repository. Workload running in a removed namespace are not terminated.resource quotas
andlimit ranges