github.com/projectcontour/contour@v1.28.2/site/content/guides/deploy-aws-tls-nlb.md (about)

     1  ---
     2  title: AWS Network Load Balancer TLS Termination with Contour
     3  layout: page
     4  ---
     5  
     6  ## Motivation
     7  
     8  ![diagram illustrating connection between network load balancer and contour](/img/aws-nlb-tls/fig.jpg){:class="img-fluid"}
     9  
    10  Managing TLS certificates (and related configuration) for production cluster workloads is both time consuming, and high risk. For example, storing multiple copies of a certificate secret key in the cluster may increases the chances of it being compromised. Additionally, TLS can be complicated to configure and implement properly. 
    11  
    12  Traditionally, TLS termination at the load balancer step required using more expensive application load balancers (ALBs). AWS introduced TLS termination for network load balancers (NLBs) for enhanced security and cost effectiveness. 
    13  
    14  The TLS implementation used by the AWS NLB is formally verified and maintained. Additionally, AWS Certificate Manager (ACM) is used, fully isolating your cluster from access to the private key. 
    15  
    16  ## Solution Overview
    17  
    18  An external client transmits a request to the NLB. The request is encrypted with TLS using the production (e.g., client facing) certificate, and on port 443. 
    19  
    20  The NLB decrypts the request, and transmits it on to your cluster on port 80. It follows the standard request routing configured within the cluster. Notably, the request received within the cluster includes the actual origin IP address of the external client. 
    21  
    22  Alternate ports may be configured. End-to-end encryption technically requires the segment between the NLB and cluster pods be encrypted also. A follow-up post will describe the NLB originating TLS based on a cluster certificate. 
    23  
    24  ## Steps
    25  
    26  ### Prerequisites
    27  
    28  1. Access to DNS records for domain name.
    29  
    30  [Review the docs on registering domains with AWS's Route 53.](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/registrar.html)
    31  
    32  An alternate DNS provider may be used, such as Google Domains or Namecheap.
    33  
    34  Later, a subdomain (e.g., demo-service.gcline.us) will be created, pointing to the NLB. Additionally, access to the DNS records is required to generate a TLS certificate for use by the NLB. 
    35  
    36  3. Verify [Contour is installed in the cluster.](https://projectcontour.io/getting-started/)
    37  
    38  4. Install [AWS Load Balancer Controller.]( https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/deploy/installation/)
    39  
    40  Generally, setting up the Load Balancer Controller has two steps: enabling IAM roles for service accounts, and adding the controller to the cluster. The IAM role allows the controller in the Kubernetes cluster to manage AWS resources. [Learn more about IAM roles for service accounts.](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html)
    41  
    42  ### Configure
    43  
    44  1. Generate TLS Certificate
    45  
    46  Create a public TLS certificate for the domain using AWS Certificate Manager (ACM). This is streamlined when the domain is managed by Route 53. Review the [AWS Certificate Manager Docs.](https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html#request-public-console)
    47  
    48  The domain name on the TLS certificate must correspond to the planned domain name for the kubernetes service. The domain name may be specified explicitly (e.g., tls-demo.gcline.us), or a wildcard certificate can be used (e.g., *.gcline.us).
    49  
    50  If the domain is registered with Route53, the TLS certificate request will automatically be approved. Otherwise, follow ACM console the instructions to create a DNS record to validate the domain. 
    51  
    52  After validation, the certificate will be available for use in your AWS account. 
    53  
    54  Note the ARN of the certificate, which uniquely identifies it in kubernetes config files. 
    55  
    56  ![screenshot indicating location of ARN value in web console](/img/aws-nlb-tls/acm-arn.png){:class="img-fluid"}
    57  
    58  2. Create Envoy Service with new NLB
    59  
    60  Contour expects a kubernetes service pointing to Envoy. Add annotations to the service to enable NLB TLS termination, before the traffic reaches Envoy. The annotations are actioned by the load balancer controller. [Review all the NLB annotations on GitHub.](https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/guide/service/annotations/)
    61  
    62  | annotation name | value | meaning | 
    63  | ----- | --- | ----- |
    64  | service.beta.kubernetes.io/aws-load-balancer-type | external | explicitly requires an NLB, instead of an ALB |
    65  | service.beta.kubernetes.io/aws-load-balancer-nlb-target-type | ip | route traffic directly to the pod IP |
    66  | service.beta.kubernetes.io/aws-load-balancer-scheme | internet-facing | An internet-facing load balancer has a publicly resolvable DNS name |
    67  | service.beta.kubernetes.io/aws-load-balancer-ssl-cert | "arn:aws:acm:..." | identifies the TLS certificate used by the NLB |
    68  | service.beta.kubernetes.io/aws-load-balancer-ssl-ports | 443 | determines the port the NLB should listen for TLS traffic on| 
    69  
    70  Example: 
    71  
    72  ```
    73  apiVersion: v1
    74  kind: Service
    75  metadata:
    76    name: envoy
    77    namespace: projectcontour
    78    annotations:
    79      service.beta.kubernetes.io/aws-load-balancer-type: external
    80      service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
    81      service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
    82      service.beta.kubernetes.io/aws-load-balancer-ssl-cert: "arn:aws:acm:us-east-2:185309785115:certificate/7610ed7d-5a81-4ea2-a18a-7ba1606cca3e"
    83      service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "443"
    84  spec:
    85    externalTrafficPolicy: Local
    86    ports:
    87    - port: 443
    88      targetPort: 8080
    89      name: http
    90      protocol: TCP
    91    selector:
    92      app: envoy
    93    type: LoadBalancer
    94  ```
    95  
    96  *Note:* Don't modify an existing service to add NLB TLS termination. This may result in unexpected behavior, such as duplicate NLB resources or incorrect NLB configuration. 
    97  
    98  3. Configure DNS
    99  
   100  **Get domain name using kubectl.** 
   101  
   102  The service name and namespace were defined above.
   103  
   104  ```
   105  kubectl get svc envoy --namespace projectcontour
   106  ```
   107  
   108  ```
   109  NAME    TYPE           CLUSTER-IP      EXTERNAL-IP                                                                     PORT(S)        AGE
   110  envoy   LoadBalancer   10.100.24.154   a7ea2bbde8a164036a7e4c1ed5700cdf-154fb911d990bb1f.elb.us-east-2.amazonaws.com   443:31606/TCP   40d
   111  ```
   112  
   113  Note the last 4 digits of the domain name for the NLB. For example, "bb1f". 
   114  
   115  **Setup DNS alias for NLB**
   116  
   117  Create a DNS record pointing from a friendly name (e.g., tls-demo.gcline.us) to the NLB domain (e.g., bb1f.elb.us-east-2.amazonaws.com). 
   118  
   119  For AWS's Route 53, follow the instructions below. If you use a different DNS provider, follow their instructions for [creating a CNAME record](https://docs.digitalocean.com/products/networking/dns/how-to/manage-records/#cname-records). 
   120  
   121  First, create a new record in Route 53. 
   122  
   123  Use the "A" record type, and enable the ["alias" option.](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resource-record-sets-values-alias.html) This option attaches the DNS record to the AWS resource, without requiring an extra lookup step for clients. 
   124  
   125  Select the NLB resource. Double check the region, and use the last 4 digits (noted earlier) to select the proper resource. 
   126  
   127  ![screenshot of Route 53 New Record Console](/img/aws-nlb-tls/record.png){:class="img-fluid"}
   128  
   129  ### Verify
   130  
   131  Attempt to access the NLB domain at port 443 with HTTPS/TLS. Is the connection successful? What certificate is used? Does it reach the expected endpoint within the cluster? 
   132  
   133  ### Next Steps
   134  
   135  Create a second TLS certificate within the cluster, for securing connections between the NLB and pods. A guide on this topic is forthcoming.
   136