Skip to main content
Skip table of contents

Make a DKP-CLI-created Cluster Managed

These pages refer to DKP Enterprise and DKP Gov Advanced products.

Manually Attach a DKP CLI Cluster to the Management Cluster

These steps are only applicable if you do not set a WORKSPACE_NAMESPACE when creating a cluster. If you already set a WORKSPACE_NAMESPACE, then you do not need to perform these steps since the cluster is already attached to the workspace.

Starting with DKP 2.6, when you create a Managed Cluster with the DKP CLI, it attaches automatically to the Management Cluster after a few moments.

However, if you do not set a workspace, the attached cluster will be created in the default workspace. To ensure that the attached cluster is created in your desired workspace namespace, follow these instructions:

  1. Confirm you have your MANAGED_CLUSTER_NAME variable set with the following command:

    CODE
    echo ${MANAGED_CLUSTER_NAME}
  2. Retrieve your kubeconfig from the cluster you have created without setting a workspace:

    CODE
    dkp get kubeconfig --cluster-name ${MANAGED_CLUSTER_NAME} > ${MANAGED_CLUSTER_NAME}.conf
  3. You can now either [attach it in the UI](link to attaching it to workspace via UI that was earlier), or attach your cluster to the workspace you want in the CLI.
    NOTE: This is only necessary if you never set the workspace of your cluster upon creation.

  4. Retrieve the workspace where you want to attach the cluster:

    CODE
    kubectl get workspaces -A
  5. Set the WORKSPACE_NAMESPACE environment variable:

    CODE
    export WORKSPACE_NAMESPACE=<workspace-namespace>
  6. You need to create a secret in the desired workspace before attaching the cluster to that workspace. Retrieve the kubeconfig secret value of your cluster:

    CODE
    kubectl -n default get secret ${MANAGED_CLUSTER_NAME}-kubeconfig -o go-template='{{.data.value}}{{ "\n"}}'
  7. This will return a lengthy value. Copy this entire string for a secret using the template below as a reference. Create a new attached-cluster-kubeconfig.yaml file:

    CODE
    apiVersion: v1
    kind: Secret
    metadata:
      name: <your-managed-cluster-name>-kubeconfig
      labels:
        cluster.x-k8s.io/cluster-name: <your-managed-cluster-name>
    type: cluster.x-k8s.io/secret
    data:
      value: <value-you-copied-from-secret-above>
  8. Create this secret in the desired workspace:

    CODE
    kubectl apply -f attached-cluster-kubeconfig.yaml --namespace ${WORKSPACE_NAMESPACE}
  9. Create this kommandercluster object to attach the cluster to the workspace:

    CODE
    cat << EOF | kubectl apply -f -
    apiVersion: kommander.mesosphere.io/v1beta1
    kind: KommanderCluster
    metadata:
      name: ${MANAGED_CLUSTER_NAME}
      namespace: ${WORKSPACE_NAMESPACE}
    spec:
      kubeconfigRef:
        name: ${MANAGED_CLUSTER_NAME}-kubeconfig
      clusterRef:
        capiCluster:
          name: ${MANAGED_CLUSTER_NAME}
    EOF
  10. You can now view this cluster in your Workspace in the UI and you can confirm its status by running the below command. It may take a few minutes to reach "Joined" status:

    CODE
    kubectl get kommanderclusters -A

If you have several Essential Clusters and want to turn one of them to a Managed Cluster to be centrally administrated by a Management Cluster, refer to Platform Expansion: Convert a DKP Essential Cluster to a DKP Enterprise Managed Cluster.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.