Namespaces¶
When deploying workloads, Threeport can manage Kubernetes namespaces for you. This is the recommended approach.
Prerequisites¶
For this guide you will need a Threeport control plane installed. Follow the Install Threeport Locally guide to install a local control plane.
Unmanaged Namespaces¶
If you do not want Threeport to manage Kubernetes namespaces for you, you will
need to include the Namespace resource in the workload definition's
YAMLDocument
that provides the manifest of Kubernetes resources.
To demonstrate, create a work space on your local file system.
1 2 |
|
Create a very simple Kubernetes manifest to deploy a pod into a namespace.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
This Kubernetes manifest includes a Namespace resource and the Pod resource must
have its metadata.namespace
set to the same namespace. This is an example of
the user managing the namespace, not Threeport.
Next we'll need workload configs for Threeport. Let's create the WorkloadDefinition.
1 2 3 4 5 |
|
And a WorkloadInstance.
1 2 3 4 5 6 |
|
Now let's create those workload resources.
1 2 |
|
We can now see the objects we created in Threeport.
1 |
|
You should see the following output.
1 2 |
|
If you have kubectl installed, you can see the pod resource in Kubernetes as well.
1 |
|
Now let's attempt to create a second instance of this workload. We'll create a second workload instance that references the same workload definition.
1 2 3 4 5 6 |
|
When you create the workload instance you will get an error.
1 |
|
This is because the workload definition for this instance contains a namespace. Another namespace with the same name cannot be created in Kubernetes so a new, distinct workload using this manifest is impossible.
In order to create multiple workload instances in a Kubernetes runtime from a single definition, use managed namespaces in Threeport.
Managed Namespaces¶
The recommended approach is to use managed namespaces in Threeport.
To demonstrate, create a very simple Kubernetes manifest to deploy a pod.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
This Kubernetes manifest includes only the Pod resource without any reference to a namespace. In this case, Threeport will manage the namespace for you so you don't need to include the Namespace resource.
Next we'll need workload configs for Threeport. Let's create the WorkloadDefinition.
1 2 3 4 5 |
|
And a WorkloadInstance.
1 2 3 4 5 6 |
|
Now let's create those workload resources.
1 2 |
|
List the Threeport workloads.
1 |
|
You should see the following output.
1 2 3 |
|
If you have kubectl installed, you can query the namespaces and see a new namespace has been created.
1 |
|
There will be a new namespace called something like
managed-nginx-0-4g0i0kshyu
. Yours will be slightly different because
Threeport puts a random suffix on the namespace name. This namespace is where
the nginx pod is running.
Now we can create a second instance of this workload. We'll create a second workload instance that references the same workload definition.
1 2 3 4 5 6 |
|
And you can now successfully create a second instance.
1 |
|
Now you can list Threeport workloads again.
1 |
|
You should see the following:
1 2 3 4 |
|
Notice there are two instances of the managed-nginx
workload derived from the
same workload definition.
You can also re-check the namespaces in your cluster.
1 |
|
You should see results similar to this:
1 2 3 |
|
In this way, using managed namespaces, you are free to deploy as many workload instances to a Kubernetes cluster from a common workload definition as you wish. When using unmanaged namespaces you are limited to one workload instance per workload definition in a single Kubernetes runtime instance.
Summary¶
In this guide you have seen how to use managed namespaces in Threeport and the utility they provide in allowing you to deploy as many workload instances from a single workload definition to a single Kubernetes runtime instance as you like.
Clean up.
1 2 |
|