View Kubernetes objects in a namespace
Estimated reading time: 3 minutesWith Docker Enterprise Edition, administrators can filter the view of Kubernetes objects by the namespace the objects are assigned to. You can specify a single namespace, or you can specify all available namespaces.
Create two namespaces
In this example, you create two Kubernetes namespaces and deploy a service to both of them.
- Log in to the UCP web UI with an administrator account.
- In the left pane, click Kubernetes.
- Click Create to open the Create Kubernetes Object page.
-
In the Object YAML editor, paste the following YAML.
apiVersion: v1 kind: Namespace metadata: name: blue --- apiVersion: v1 kind: Namespace metadata: name: green
- Click Create to create the
blue
andgreen
namespaces.
Deploy services
Create a NodePort
service in the blue
namespace.
- Navigate to the Create Kubernetes Object page.
- In the Namespace dropdown, select blue.
-
In the Object YAML editor, paste the following YAML.
apiVersion: v1 kind: Service metadata: name: app-service-blue labels: app: app-blue spec: type: NodePort ports: - port: 80 nodePort: 32768 selector: app: app-blue
-
Click Create to deploy the service in the
blue
namespace. -
Repeat the previous steps with the following YAML, but this time, select
green
from the Namespace dropdown.apiVersion: v1 kind: Service metadata: name: app-service-green labels: app: app-green spec: type: NodePort ports: - port: 80 nodePort: 32769 selector: app: app-green
View services
Currently, the Namespaces view is set to the default namespace, so the Load Balancers page doesn’t show your services.
- In the left pane, click Namespaces to open the list of namespaces.
- In the upper-right corner, click the Set context for all namespaces toggle and click Confirm. The indicator in the left pane changes to All Namespaces.
- Click Load Balancers to view your services.
Filter the view by namespace
With the Set context for all namespaces toggle set, you see all of the Kubernetes objects in every namespace. Now filter the view to show only objects in one namespace.
- In the left pane, click Namespaces to open the list of namespaces.
-
In the green namespace, click the More options icon and in the context menu, select Set Context.
- Click Confirm to set the context to the
green
namespace. The indicator in the left pane changes to green. - Click Load Balancers to view your
app-service-green
service. Theapp-service-blue
service doesn’t appear.
To view the app-service-blue
service, repeat the previous steps, but this
time, select Set Context on the blue namespace.