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
occommands. 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
oc loginCopy to Clipboard Copied! Toggle word wrap Toggle overflow 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.yamlfile file and commands:oc new-project ${CLUSTER_NAME} oc label namespace ${CLUSTER_NAME} cluster.open-cluster-management.io/managedCluster=${CLUSTER_NAME}oc new-project ${CLUSTER_NAME} oc label namespace ${CLUSTER_NAME} cluster.open-cluster-management.io/managedCluster=${CLUSTER_NAME}Copy to Clipboard Copied! Toggle word wrap Toggle overflow Edit the example ManagedCluster with the following sample of YAML:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Save the file as
managed-cluster.yaml. Apply the YAML file with the following command:
oc apply -f managed-cluster.yaml
oc apply -f managed-cluster.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the klusterlet addon configuration file. Enter the following example YAML:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Save the file as
klusterlet-addon-config.yaml. Apply the YAML. Run the following command:
oc apply -f klusterlet-addon-config.yaml
oc apply -f klusterlet-addon-config.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
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.yamlthat 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.yamloc get secret ${CLUSTER_NAME}-import -n ${CLUSTER_NAME} -o jsonpath={.data.crds\\.yaml} | base64 --decode > klusterlet-crd.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Obtain the
import.yamlthat 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.yamloc get secret ${CLUSTER_NAME}-import -n ${CLUSTER_NAME} -o jsonpath={.data.import\\.yaml} | base64 --decode > import.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Log in to your target managed cluster.
Apply the
klusterlet-crd.yamlthat was generated in step 1. Run the following command:kubectl apply -f klusterlet-crd.yaml
kubectl apply -f klusterlet-crd.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the
import.yamlfile that was generated in step 2. Run the following command:kubectl apply -f import.yaml
kubectl apply -f import.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Validate the pod status on the target managed cluster. Run the following command:
kubectl get pod -n open-cluster-management-agent
kubectl get pod -n open-cluster-management-agentCopy to Clipboard Copied! Toggle word wrap Toggle overflow Validate
JOINEDandAVAILABLEstatus for your imported cluster. Run the following command from the hub cluster:kubectl get managedcluster -n ${CLUSTER_NAME}kubectl get managedcluster -n ${CLUSTER_NAME}Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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
kubectl get pod -n open-cluster-management-agent-addonCopy to Clipboard Copied! Toggle word wrap Toggle overflow