8.2. Importing a managed cluster with the CLI
After you install Red Hat Advanced Cluster Management for Kubernetes, you are ready to import a cluster to manage. You can import from both the console and the CLI. Follow this procedure to import from the CLI.
A hub cluster cannot manage another hub cluster.
8.2.1. Prerequisites
- You need a Red Hat Advanced Cluster Management for Kubernetes hub cluster that is deployed. If you are importing bare metal clusters, you must have the hub cluster installed on Red Hat OpenShift Container Platform version 4.4, or later. Important: The bare metal function is a technology preview, and should not be used in production enviromnents.
- You need a separate cluster that you want to manage and Internet connectivity.
-
You need the Red Hat OpenShift Container Platform CLI version 4.3, or later, to run
oc
commands. See Getting started with the CLI for information about installing and configuring the Red Hat OpenShift CLI,oc
. You need to install the Kubernetes CLI,
kubectl
. To installkubectl
, see Install and Set Up kubectl in the Kubernetes documentation.注意Download the installation file for CLI tools from the console.
8.2.2. Supported architecture
- Linux
- macOS
8.2.3. Prepare for import
Log in to your hub cluster. Run the following command:
oc login
Run the following command on the hub cluster to create the namespace. Note: The cluster name that is defined in
<cluster_name>
is also used as the cluster namespace in the.yaml
file file and commands:oc new-project ${CLUSTER_NAME} oc label namespace ${CLUSTER_NAME} cluster.open-cluster-management.io/managedCluster=${CLUSTER_NAME}
Edit the example ManagedCluster with the following sample of YAML:
apiVersion: cluster.open-cluster-management.io/v1 kind: ManagedCluster metadata: name: <cluster_name> spec: hubAcceptsClient: true
-
Save the file as
managed-cluster.yaml
. Apply the YAML file with the following command:
oc apply -f managed-cluster.yaml
Create the klusterlet addon configuration file. Enter the following example YAML:
apiVersion: agent.open-cluster-management.io/v1 kind: KlusterletAddonConfig metadata: name: <cluster_name> namespace: <cluster_name> spec: clusterName: <cluster_name> clusterNamespace: <cluster_name> applicationManager: enabled: true certPolicyController: enabled: true clusterLabels: cloud: auto-detect vendor: auto-detect iamPolicyController: enabled: true policyController: enabled: true searchCollector: enabled: true version: 2.0.0
-
Save the file as
klusterlet-addon-config.yaml
. Apply the YAML. Run the following command:
oc apply -f klusterlet-addon-config.yaml
The ManagedCluster-Import-Controller will generate a secret named ${CLUSTER_NAME}-import
. The ${CLUSTER_NAME}-import
secret contains the import.yaml
that the user applies to a managed cluster to install klusterlet.
8.2.4. Importing the klusterlet
The import command contains pull secret information that is copied to each of the imported clusters. Anyone who can access the imported clusters can also view the pull secret information.
Obtain the
klusterlet-crd.yaml
that was generated by the managed cluster import controller.Run the following command:
oc get secret ${CLUSTER_NAME}-import -n ${CLUSTER_NAME} -o jsonpath={.data.crds\\.yaml} | base64 --decode > klusterlet-crd.yaml
Obtain the
import.yaml
that was generated by the managed cluster import controller. Run the following command:oc get secret ${CLUSTER_NAME}-import -n ${CLUSTER_NAME} -o jsonpath={.data.import\\.yaml} | base64 --decode > import.yaml
- Log in to your target managed cluster.
Apply the
klusterlet-crd.yaml
that was generated in step 1. Run the following command:kubectl apply -f klusterlet-crd.yaml
Apply the
import.yaml
file that was generated in step 2. Run the following command:kubectl apply -f import.yaml
Validate the pod status on the target managed cluster. Run the following command:
kubectl get pod -n open-cluster-management-agent
Validate
JOINED
andAVAILABLE
status for your imported cluster. Run the following command from the hub cluster:kubectl get managedcluster -n ${CLUSTER_NAME}
Addons will be installed after the managed cluster is
AVAILABLE
. Validate the pod status of addons on the target managed cluster. Run the following command:kubectl get pod -n open-cluster-management-agent-addon