// Module included in the following assemblies:
//
// * installing/installing_gcp/installing-gcp-user-infra.adoc
// * installing/installing_gcp/installing-gcp-user-infra-vpc.adoc

:_mod-docs-content-type: PROCEDURE
[id="installation-creating-gcp-lb_{context}"]
= Creating load balancers in {gcp-short}

[role="_abstract"]
You must configure load balancers in {gcp-first} for your {product-title} cluster to use. One way to create these components is to modify the provided Infrastructure Manager template.

[NOTE]
====
If you do not use the provided template to create your {gcp-short} infrastructure, you must review the provided information and manually create the infrastructure.
If your cluster does not initialize correctly, you might have to contact Red Hat support with your installation logs.
====

.Prerequisites

* You have defined the variables in the _Exporting common variables_ section.
* If you are not installing a cluster into a shared VPC, you have defined the variables in the _Creating a VPC in {gcp-short}_ section.

.Procedure

. If you are installing a cluster into a shared VPC, set environment variables for the cluster network and control plane subnet.

.. Determine the shared VPC network name by running the following command:
+
[source,terminal]
----
$ gcloud compute networks list
----

.. Set the `CLUSTER_NETWORK` variable by running the following command:
+
[source,terminal]
----
$ export CLUSTER_NETWORK=$(gcloud compute networks describe <network_name> --format json | jq -r .selfLink)
----
+
`<network_name>` specifies the name of the network you determined.

.. List the available network subnets by running the following command:
+
[source,terminal]
----
$ gcloud compute networks subnets list --network=<network_name>
----
`<network_name>` specifies the name of the network you determined.

.. Select a subnet from the list, and set the `CONTROL_SUBNET` variable by running the following command:
+
[source,terminal]
----
$ export CONTROL_SUBNET=<control_subnet>
----
+
`<control_subnet>` specifies the name of the subnet you selected from the list of subnets.

. Copy the template from the *Infrastructure Manager template for the internal load balancer* section of this topic and save it as `02_lb_int.tf` in a directory called `02_lb_int` on your computer. This template describes the internal load balancing objects that your cluster requires.

.. Create an internal load balancer by running the following command:
+
[source,terminal]
----
$ gcloud infra-manager deployments apply <internal_lb_deployment_name> \
  --location=${REGION} \
  --input-values=infra_id=${INFRA_ID},project=${PROJECT_NAME},region=${REGION},cluster_network=${CLUSTER_NETWORK},control_subnet=${CONTROL_SUBNET},zone_0=${ZONE_0},zone_1=${ZONE_1},zone_2=${ZONE_2} \
  --project=${PROJECT_NAME} \
  --local-source=./02_lb_int \
  --service-account=${INSTALL_SERVICE_ACCOUNT}
----
+
`<internal_lb_deployment_name>` specifies the name of the internal load balancer deployment you create.

.. Export the `CLUSTER_IP` variable by running the following command:
+
[source,terminal]
----
$ export CLUSTER_IP=$(gcloud compute addresses describe ${INFRA_ID}-cluster-ip --region=${REGION} --format json | jq -r .address)
----

. Optional: For a public or externally available cluster, copy the template from the *Infrastructure Manager template for the external load balancer* section of this topic and save it as `02_lb_ext.tf` in a directory called `02_lb_ext` on your computer. This template describes the external load balancing objects that your cluster requires.

.. Create an external load balancer by running the following command:
+
[source,terminal]
----
$ gcloud infra-manager deployments apply <external_lb_deployment_name> \
  --location=${REGION} \
  --input-values=infra_id=${INFRA_ID},project=${PROJECT_NAME},region=${REGION} \
  --project=${PROJECT_NAME} \
  --local-source=./02_lb_ext \
  --service-account=${INSTALL_SERVICE_ACCOUNT}
----
+
`<external_lb_deployment_name>` specifies the name of the external load balancer deployment you create.

.. Export the `CLUSTER_PUBLIC_IP` variable by running the following command:
+
[source,terminal]
----
$ export CLUSTER_PUBLIC_IP=$(gcloud compute addresses describe ${INFRA_ID}-cluster-public-ip --region=${REGION} --format json | jq -r .address)
----

.Verification

include::snippets/gcp-infra-manager-deployment-verify.adoc[]