// Module included in the following assemblies:
//
// * hosted_control_planes/hcp-deploy/hcp-deploy-ibmz.adoc

:_mod-docs-content-type: PROCEDURE
[id="hcp-ibmz-create-hc_{context}"]
= Creating a hosted cluster on bare metal for {ibm-z-title}

[role="_abstract"]
On bare-metal infrastructure, you can create or import a hosted cluster. After you enable the Assisted Installer as an add-on to {mce-short} and you create a hosted cluster with the Agent platform, the HyperShift Operator installs the Agent Cluster API provider in the hosted control plane namespace. The Agent Cluster API provider connects a management cluster that hosts the control plane and a hosted cluster that consists of only the compute nodes. 

.Prerequisites

- Each hosted cluster must have a cluster-wide unique name. A hosted cluster name cannot be the same as any existing managed cluster. Otherwise, the {mce-short} cannot manage the hosted cluster.

- Do not use the word `clusters` as a hosted cluster name.

- You cannot create a hosted cluster in the namespace of a {mce-short} managed cluster.

- For best security and management practices, create a hosted cluster separate from other hosted clusters. 

- Verify that you have a default storage class configured for your cluster. Otherwise, you might see pending persistent volume claims (PVCs).

.Procedure

. Create a namespace by entering the following command:
+
[source,terminal]
----
$ oc create ns <hosted_cluster_namespace>
----
+
Replace `<hosted_cluster_namespace>` with an identifier for your hosted cluster namespace. The HyperShift Operator creates the namespace. During the hosted cluster creation process on bare-metal infrastructure, a generated Cluster API provider role requires that the namespace already exists.

. Create the configuration file for your hosted cluster by entering the following command:
+
[source,terminal]
----
$ hcp create cluster agent \
  --name=<hosted_cluster_name> \
  --pull-secret=<path_to_pull_secret> \
  --agent-namespace=<hosted_control_plane_namespace> \
  --base-domain=<base_domain> \
  --api-server-address=api.<hosted_cluster_name>.<base_domain> \
  --etcd-storage-class=<etcd_storage_class> \
  --ssh-key=<path_to_ssh_key> \
  --namespace=<hosted_cluster_namespace> \
  --control-plane-availability-policy=HighlyAvailable \
  --release-image=quay.io/openshift-release-dev/ocp-release:<ocp_release_image>-multi \
  --node-pool-replicas=<node_pool_replica_count> \
  --disable-cluster-capabilities=<capability> \
  --enable-cluster-capabilities=<capability> \
  --render \
  --render-sensitive  > hosted-cluster-config.yaml
----
+
where:
+
* `--name` specifies the name of your hosted cluster, such as `example`.
* `--pull-secret` specifies the path to your pull secret, such as `/user/name/pullsecret`.
* `--agent-namespace` specifies your hosted control plane namespace, such as `clusters-example`. Ensure that agents are available in this namespace by using the `oc get agent -n <hosted_control_plane_namespace>` command.
* `--base-domain` specifies your base domain, such as `krnl.es`.
* `--api-server-address` specifies the IP address that gets used for the Kubernetes API communication in the hosted cluster. If you do not set the `--api-server-address` flag, you must log in to connect to the management cluster.
* `--etcd-storage-class` specifies the etcd storage class name, such as `lvm-storageclass`.
* `--ssh-key` specifies the path to your SSH public key. The default file path is `~/.ssh/id_rsa.pub`.
* `--namespace` specifies your hosted cluster namespace.
* `--control-plane-availability-policy` specifies the availability policy for the hosted control plane components. Supported options are `SingleReplica` and `HighlyAvailable`. The default value is `HighlyAvailable`.
* `--release-image` specifies the supported {product-title} version that you want to use, such as `4.22.0-multi`. If you are using a disconnected environment, replace `<ocp_release_image>` with the digest image. To extract the {product-title} release image digest, see "Extracting the release image digest".
* `--node-pool-replicas` specifies the node pool replica count, such as `3`. You must specify the replica count as `0` or greater to create the same number of replicas. Otherwise, you do not create node pools.
* `--disable-cluster-capabilities` specifies that you want to disable optional capabilities in the hosted cluster. This flag is optional. For more information, see "Capabilities for hosted clusters".
* `--enable-cluster-capabilities` specifies that you want to enable optional capabilities in the hosted cluster. This flag is optional. For more information, see "Capabilities for hosted clusters".

. Apply the changes to the hosted cluster configuration file by entering the following command:
+
[source,terminal]
----
$ oc apply -f hosted_cluster_config.yaml
----

. Check for the creation of the hosted cluster, node pools, and pods by entering the following commands:
+
[source,terminal]
----
$ oc get hostedcluster \
  <hosted_cluster_name> -n \
  <hosted_cluster_namespace> -o \
  jsonpath='{.status.conditions[?(@.status=="False")]}' | jq .
----
+
[source,terminal]
----
$ oc get hostedcluster \
  <nodepool_name> -n \
  <hosted_cluster_namespace> -o \
  jsonpath='{.status.conditions[?(@.status=="False")]}' | jq .
----
+
[source,terminal]
----
$ oc get pods -n <hosted_control_plane_namespace>
----

. Confirm that the hosted cluster is ready. The status of `Available: True` indicates the readiness of the control plane.