A new version of Anthos GKE on AWS was released on August 5. See the release notes for information on breaking changes.

Preparing AWS networking

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.

Before you begin

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

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 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. Use anthos-gke to switch context to your management service.

    anthos-gke aws management get-credentials

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

     export VPC_ID=$(\
     env HTTP_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.

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

    export CLUSTER_ID=$(\
    env HTTP_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. By default, GKE on AWS sets up a VPC with private and public subnets. To retrieve the subnet ID, use the aws command line tool.

    Select from the following options:

    • Public: If you wish to expose Services on your public Subnet.
    • Private: If you wish to expose Services on your private Subnet.
    • Multiple subnets: If you wish to expose Services on multiple subnets.

    Public

     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

     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.

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

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

    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:

    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

    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:

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

    Replace subnet-ids with the list of subnet IDs, separated by spaces. For example, subnet-012345678abcdef subnet-abcdef123456789 subnet-123456789abcdef.