When creating a self-managed cluster, the default settings are to pivot your CAPI resources to the Kubernetes "default" namespace. Depending on the scenario, this is not always compliant with organizational requirements or best practices. While the "--namespace" flag is not natively supported when issuing a 'dkp move' command, you can create a context set to your desired namespace. This then pivots the CAPI resources from your bootstrap cluster to your management cluster to your desired namespace. To do this, you can follow the steps below:
-
Create your bootstrap cluster:
dkp create bootstrap
-
Create the namespace you want to deploy your cluster to:
kubectl create namespace <name>
-
Create the YAML for your management cluster:
dkp create cluster <provider> \
--cluster-name=${CLUSTER_NAME} \
--namespace <name> \
--dry-run -oyaml > cluster.yaml -
Set your current context to the created namespace:
kubectl config set-context --current --namespace=<name>
-
Create your cluster:
kubectl create -f cluster.yaml
-
Validate your cluster has deployed:
dkp describe cluster --cluster-name ${CLUSTER_NAME} -n <name>
-
Gather the Kubeconfig from your new cluster:
dkp get kubeconfig -c ${CLUSTER_NAME} -n <name> > cluster.conf
-
Create the namespace you want your CAPI components in:
kubectl create ns <name> --kubeconfig cluster.conf
-
Set the context of that kubeconfig to the created namespace:
kubectl config set-context --current --namespace=<name> --kubeconfig cluster.conf
-
Create the CAPI components on the management cluster:
dkp create capi-components --kubeconfig cluster.conf
-
Move the CAPI resources to your new cluster:
dkp move capi-resources --to-kubeconfig cluster.conf
- Validate your resources have been moved to the correct namespace:
kubectl get cluster -n <test>