CLI
The RCTL utility provides the means to manage the lifecycle of namespaces across the fleet of managed clusters. The following operations can be performed on namespaces managed by the controller on the fleet of clusters.
Resource | Create | Get | Update | Delete | Status | Publish |
---|---|---|---|---|---|---|
Namespace | YES | YES | YES | YES | YES | YES |
Managed Namespaces¶
As a multi cluster operations platform, the Controller creates/deletes namespaces on managed Kubernetes clusters.
For immediate operations on a namespace on a cluster, use the Zero Trust KubeCTL to manage these directly.
Create Namespace¶
Namespace can be created in three (3) types
- Namespace Wizard
- Repo
- Upload
Deploying the namespace can be done for a specific cluster or by cluster labels. For placement on specific cluster use placementType: ClusterSpecific For labels use placementType: ClusterLabels
Create a new "managed" namespace in the current Project using the Yaml config spec
Declarative¶
To create/update a namespace with the declarative method, use the below command
./rctl apply -f namespace.yaml
Type: RafayWizard
Below is an example of namespace yaml file with the type RafayWizard and placementType ClusterSpecific
kind: Namespace
apiVersion: infra.k8smgmt.io/v3
metadata:
name: abc
description: desc-01
project: defaultproject
labels:
env: dev
priority: high
severity: low
annotations:
a1: v3
a2: v4
spec:
type: RafayWizard
resourceQuota:
cpuRequests: 2
memoryRequests: 2
cpuLimits: 1
memoryLimits: 2
limitRange:
podLimits:
maxCpu: 3
maxMemory: 2
minCpu: 1
minMemory: 1
maxLimitRequestRatioCpu: 1
maxLimitRequestRatioMemory: 1
containerLimits:
maxCpu: 2
maxMemory: 2
minCpu: 2
minMemory: 2
defaultCpu: 2
defaultMemory: 2
defaultRequestCpu: 2
defaultRequestMemory: 2
maxLimitRequestRatioCpu: 1
maxLimitRequestRatioMemory: 1
placement:
labels:
- key: rafay.dev/clusterName
value: demo-cluster-01
Type: Repo
Below is an example of namespace yaml file with the type Repo and placementType ClusterLabels
kind: Namespace
apiVersion: infra.k8smgmt.io/v3
metadata:
name:rctl-repo2
project: defaultproject
spec:
type: Repo
repoRef:git-cred
repoArtifactMeta:
git:
revision: main3
repoArtifactFiles:
- name: abc.yaml
relPath: NameSpace/abc.yaml
fileType: K8sYAMLFile
placement:
labels:
- key: rafay.dev/clusterId
value: qweed
Type: Upload
Below is an example of namespace yaml file with the type Upload and placementType ClusterSpecific
kind: Namespace
apiVersion: infra.k8smgmt.io/v3
metadata:
name: upload-ns-03
project: defaultproject
spec:
type: Upload
namespaceFromFile: "/Users/Downloads/abc.yaml"
placement:
labels:
- key: rafay.dev/clusterName
value: xyz
Important
Avoid upper case characters for the name because Kubernetes does not support it
List Namespace¶
The below command is to retrieve/list all "managed namespaces" in the currently specified "Project".
./rctl get namespace --v3
+-------------------------+----------+--------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+
| NAME | TYPE | PLACEMENT DETAILS | LABELS | ANNOTATIONS |
+-------------------------+----------+--------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+
| new-ns | Wizard | rafay.dev/clusterName:new-prod-eks | | |
+-------------------------+----------+--------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+
| ns-1 | Wizard | rafay.dev/clusterName:new-prod-eks | | |
+-------------------------+----------+--------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+
The below command is to retrieve a specific namespace from a project. When viewing a specific namespace, labels and annotations associated with the namespace are also shown
./rctl get namespace nov-ns --v3
+--------+--------+----------------------------------------+--------+-------------+
| NAME | TYPE | PLACEMENT DETAILS | LABELS | ANNOTATIONS |
+--------+--------+----------------------------------------+--------+-------------+
| nov-ns | Wizard | rafay.dev/clusterName:prod-eks | | |
+--------+--------+----------------------------------------+--------+-------------+
Or you can use the below commands to get more information of the namespace in json or yaml format
./rctl get namespace <namespace-name> -o json
./rctl get namespace <namespace-name> -o yaml
Example:
./rctl get namespace demo-ns -o yaml
apiVersion: infra.k8smgmt.io/v3
kind: Namespace
metadata:
name: demo-ns
project: prod-test
spec:
limitRange:
container: {}
pod: {}
namespaceMeshPolicyParams: {}
placement:
labels:
- key: rafay.dev/clusterName
value: prod-eks
resourceQuotas: {}
status:
conditionStatus: 2
conditionType: NamespaceReady
lastUpdated:
nanos: 265072687
seconds: 1668838314
reason: namespace is ready
Delete Namespace¶
Delete a "managed namespace" in the current project context using the following command. Users are allowed to delete one or more namespaces at once. Below is an example of multiple namespace deletion Deleting a namespace will also delete the namespace from the clusters where the namespace is published.
./rctl delete namespace -f config.yaml
Important
Managed namespaces cannot be deleted if they are in active use by workloads or blueprints
Namespace Status¶
To know the status of a namespace, use the below command
./rctl status namespace <ns-name>
Output
+---------+------+----------------+------------------+------------------+----------------+
| NAME | TYPE | PUBLISHPENDING | ASSIGNEDCLUSTERS | DEPLOYEDCLUSTERS | FAILEDCLUSTERS |
+---------+------+----------------+------------------+------------------+----------------+
| demo | Repo | false | demo-cluster | demo-ckuster | |
+---------+------+----------------+------------------+------------------+----------------+
Note: For help commands, append -h or --help after any of these commands. Example:
.rctl get namespace -h
or.rctl get namespace --help
Templating¶
Users can also create multiple namespaces with a set of defined configurations. The template file contains a list of objects that helps to create multiple namespace(s) from a single template.
Below is an example of a namespace config template
# Generated: {{now.UTC.Format "2006-01-02T15:04:05UTC"}}
# With: {{command_line}}
{{ $envName := environment "PWD" | basename}}
{{ $glbCtx := . }}{{ range $i, $project := .ProjectNames }}
{{ $ctxNS := $glbCtx }}{{ range $j, $ns := $glbCtx.Namespaces }}
apiVersion: infra.k8smgmt.io/v3
kind: Namespace
metadata:
project: {{$envName}}-{{$project}}
name: {{ $ns.Name }}
labels:{{$q := $ctxNS}}{{range $k, $label := $ns.Labels}}
{{ $label.Key }}: {{ $label.Value }}{{end}}
environment: {{$envName}}
spec:
drift:
enabled: false
placement:
labels:{{$c := $ctxNS}}{{range $l, $cluster := $ctxNS.ClusterNames}}
- key: rafay.dev/clusterName
value: {{$envName}}-{{$project}}-{{ $cluster }}{{end}}
resourceQuotas:
configMaps: "{{ $c.ResourceQuota.ConfigMaps }}"
cpuLimits: {{ $c.ResourceQuota.CpuLimits }}
cpuRequests: {{ $c.ResourceQuota.CpuRequests }}
memoryLimits: {{ $c.ResourceQuota.MemoryLimits }}
memoryRequests: {{ $c.ResourceQuota.MemoryRequests }}
storageRequests: {{ $c.ResourceQuota.StorageRequests }}
---{{end}}
{{end}}
Users can create one or more namespace(s) with the required configuration defined in the template file. Below is an example of an namespace value file. This file helps to create namespace with the specified objects
Namespaces:
- Name: ns-frontend
Labels:
- Key: component
Value: frontend
- Key: app
Value: service-xyz
- Name: ns-backend
Labels:
- Key: component
Value: backend
- Key: app
Value: service-xyz
- Name: ns-database
Labels:
- Key: component
Value: database
- Key: app
Value: service-xyz
ResourceQuota:
ConfigMaps: "100.000000"
CpuLimits: 500.000000m
CpuRequests: 500.000000m
MemoryLimits: 500.000000Mi
MemoryRequests: 500.000000Mi
StorageRequests: "1.000000"
Important
Only the objects defined in the template must be present in the value files
Use the command below to create namespace(s) with the specified configuration once the value file(s) are prepared with the necessary objects
./rctl apply -t namespace.tmpl --values values.yaml
where, - namespace.tmpl: template file - value.yaml: value file
Refer Templating for more details on Templating flags and examples
Important
Refer here for the deprecated RCTL commands