To set up an externally facing load balancer with GKE on AWS,
you need to tag your VPC and public subnet with your cluster ID. If you
have already tagged your VPC and subnet, skip to
[Enabling Ingress](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/ingress.md.txt).

## Before you begin


Before you start using GKE on AWS, make sure you have performed the following tasks:

- Complete the [Prerequisites](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/prerequisites.md.txt).

<!-- -->

- Install a [management service](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/installing-management.md.txt).
- Create a [user cluster](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/creating-user-cluster.md.txt).

GKE on AWS requires tags on subnets that contain load balancer
endpoints. GKE on AWS automatically tags all subnets specified in the
[`spec.Networking.ServiceLoadBalancerSubnetIDs`](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/reference/awscluster.md.txt#specnetworking)
field of the `AWSCluster` resource.

If you would like to add additional subnets to your user cluster, or if you need
to re-apply tags to existing subnets, perform the following steps.

1. From your `anthos-aws` directory, use
   `anthos-gke` to switch context to your management service.

   ```sh
   cd anthos-aws
   anthos-gke aws management get-credentials
   ```

   > [!NOTE]
   > **Note:** `anthos-gke` uses the credentials you specified when you ran `aws configure`.

   <br />

2. Get the ID of your cluster's AWS VPC with `kubectl` and store it as a
   variable.

   ```bash
    export VPC_ID=$(\
    env HTTPS_PROXY=http://localhost:8118 \
    kubectl get awscluster cluster-0 -o jsonpath='{.spec.networking.vpcID}')
   ```
3. Check the variables content with `echo`. The output
   resembles `vpc-12345678abcdef0`.

   ```bash
   echo $VPC_ID
   ```
4. Save your cluster ID into an environment variable.

   ```bash
   export CLUSTER_ID=$(\
   env HTTPS_PROXY=http://localhost:8118 \
   kubectl get awscluster cluster-0 -o jsonpath='{.status.clusterID}')
   ```

   You can check the variable with `echo`:

       echo $CLUSTER_ID

   The response includes your cluster ID.

       gke-12345678

5. If you installed GKE on AWS into a dedicated VPC, you can use
   the `aws` command-line tool to retrieve the subnet ID.

   Select from the following options:
   - Public, if you want to expose Services on your public subnet.
   - Private, if you want to expose Services on your private subnet.
   - Multiple subnets, if you want to expose Services on multiple subnets.

   ### Public

   ```bash
    export SUBNET_ID=$(aws ec2 describe-subnets \
    --filters "Name=vpc-id,Values=$VPC_ID" "Name=tag:Name,Values=*public*" \
    --query "Subnets[*].SubnetId" \
    --output text)
   ```

   The output is an object that contains your subnet ID. It resembles
   `subnet-1234abcdefg`. You can check the variable with `echo`:

       echo $SUBNET_ID

   The response includes your subnet ID.

       subnet-012345678abcdef

   ### Private

   ```bash
    export SUBNET_ID=$(aws ec2 describe-subnets \
    --filters "Name=vpc-id,Values=$VPC_ID" "Name=tag:Name,Values=*private*" \
    --query "Subnets[*].SubnetId" \
    --output text)
   ```

   The output is an object that contains your subnet ID. It resembles
   `subnet-1234abcdefg`. You can check the variable with `echo`:

       echo $SUBNET_ID

   The response includes your subnet ID.

       subnet-012345678abcdef

   ### Multiple subnets

   If you are using multiple subnets for your AWSNodePools
   (for example, if you use multiple availability zones), you need to
   tag your subnet IDs individually.

   > [!NOTE]
   > **Note:** The following commands assume your subnets have `public` or `private` in their name. If your subnets do not include this text, change the parameters of the `--filters` flag. See [Using filtering](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Filtering.html) for more information.

   Retrieve your list of subnet IDs with `aws ec2 describe-subnets`.

   To get a list of all public subnets, run the following command:

   ```bash
   aws ec2 describe-subnets \
    --filters "Name=vpc-id,Values=$VPC_ID" "Name=tag:Name,Values=*public*" \
    --query "Subnets[*].SubnetId" \
    --output text
   ```

   To get a list of all private subnets, run the following command:

   ```bash
   aws ec2 describe-subnets \
    --filters "Name=vpc-id,Values=$VPC_ID" "Name=tag:Name,Values=*private*" \
    --query "Subnets[*].SubnetId" \
    --output text
   ```

   The response includes your subnet IDs.

       subnet-012345678abcdef
       subnet-abcdef123456789
       subnet-123456789abcdef

6. Tag your subnet with your cluster ID. If you have multiple subnets,
   select Multiple subnets.

   ### Single subnet

   ```bash
   aws ec2 create-tags \
   --resources $SUBNET_ID \
   --tags Key=kubernetes.io/cluster/$CLUSTER_ID,Value=shared
   ```

   ### Multiple subnets

   For each of your subnets, run the following command:

   ```bash
   aws ec2 create-tags \
   --resources subnet-ids \
   --tags Key=kubernetes.io/cluster/$CLUSTER_ID,Value=shared
   ```

   Replace <var translate="no">subnet-ids</var> with the list of subnet IDs, separated by
   spaces. For example,
   `subnet-012345678abcdef subnet-abcdef123456789 subnet-123456789abcdef`.