Kubernetes Ingress with AWS ALB Ingress Controller

by Nishi Davidson | on 20 NOV 2018 | in Amazon Elastic Kubernetes Service, Open Source | Permalink | Comments | Share

中文版 – Kubernetes Ingress is an api object that allows you manage external (or) internal HTTP[s] access to Kubernetes services running in a cluster. Amazon Elastic Load Balancing Application Load Balancer (ALB) is a popular AWS service that load balances incoming traffic at the application layer (layer 7) across multiple targets, such as Amazon EC2 instances, in a region. ALB supports multiple features including host or path based routing, TLS (Transport layer security) termination, WebSockets, HTTP/2, AWS WAF (web application firewall) integration, integrated access logs, and health checks.

The AWS ALB Ingress controller is a controller that triggers the creation of an ALB and the necessary supporting AWS resources whenever a Kubernetes user declares an Ingress resource on the cluster. The Ingress resource uses the ALB to route HTTP[s] traffic to different endpoints within the cluster. The AWS ALB Ingress controller works on any Kubernetes cluster including Amazon Elastic Container Service for Kubernetes (EKS).

Terminology

We will use the following acronyms to describe the Kubernetes Ingress concepts in more detail:

  • ALB: AWS Application Load Balancer
  • ENI: Elastic Network Interfaces
  • NodePort: When a user sets the type field to NodePort, the Kubernetes master allocates a static port from a range, and each Node will proxy that port (the same port number on every Node) into your Service.

How Kubernetes Ingress works with aws-alb-ingress-controller

The following diagram details the AWS components that the aws-alb-ingress-controller creates whenever an Ingress resource is defined by the user. The Ingress resource routes ingress traffic from the ALB to the Kubernetes cluster.

diagram: How Kubernetes Ingress works with aws-alb-ingress-controller

Ingress Creation

Following the steps in the numbered blue circles in the above diagram:

  1. The controller watches for ingress events from the API server. When it finds ingress resources that satisfy its requirements, it begins creation of AWS resources.
  2. An ALB is created for the Ingress resource.
  3. TargetGroups are created for each backend specified in the Ingress resource.
  4. Listeners are created for every port specified as Ingress resource annotation. When no port is specified, sensible defaults (80 or 443) are used.
  5. Rules are created for each path specified in your ingress resource. This ensures that traffic to a specific path is routed to the correct TargetGroup created.

Ingress Traffic

AWS ALB Ingress controller supports two traffic modes: instance mode and ip mode.
Users can explicitly specify these traffic modes by declaring the alb.ingress.kubernetes.io/target-type annotation on the Ingress and the Service definitions.

  • instance mode: Ingress traffic starts from the ALB and reaches the NodePort opened for your service. Traffic is then routed to the container Pods within cluster. The number of hops for the packet to reach its destination in this mode is always two.
  • ip mode: Ingress traffic starts from the ALB and reaches the container Pods within cluster directly. In order to use this mode, the networking plugin for the Kubernetes cluster must use a secondary IP address on ENI as pod IP, aka AWS CNI plugin for Kubernetes. The number of hops for the packet to reach its destination in this mode is always one.

Deploy Amazon EKS with eksctl

First, let’s deploy an Amazon EKS cluster with eksctl cli tool.

Install eksctl with Homebrew for macOS users:

brew install weaveworks/tap/eksctl

Create EKS cluster with cluster name “attractive-gopher”

eksctl create cluster --name=attractive-gopher

Go to the “Subnets” section in the VPC Console. Find all the Public subnets for your EKS cluster.

Example:
eksctl-attractive-gopher-cluster/SubnetPublic<USWEST2a>
eksctl-attractive-gopher-cluster/SubnetPublic<USWEST2b>
eksctl-attractive-gopher-cluster/SubnetPublic<USWEST2c>

Configure the Public subnets in the console as defined in this guide. (Most Kubernetes
distributions on AWS already do this for you, e.g. kops)

Deploy AWS ALB Ingress controller

Next, let’s deploy the AWS ALB Ingress controller into our Kubernetes cluster.

Create the IAM policy to give the Ingress controller the right permissions:

  1. Go to the IAM Console and choose the section Policies.
  2. Select Create policy.
  3. Embed the contents of the template iam-policy.json in the JSON section.
  4. Review policy and save as “ingressController-iam-policy”

Attach the IAM policy to the EKS worker nodes:

  1. Go back to the IAM Console.
  2. Choose the section Roles and search for the NodeInstanceRole of your EKS worker node. Example: eksctl-attractive-gopher-NodeInstanceRole-xxxxxx
  3. Attach policy “ingressController-iam-policy.”

Deploy RBAC Roles and RoleBindings needed by the AWS ALB Ingress controller:

kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.0.0/docs/examples/rbac-role.yaml

Download the AWS ALB Ingress controller YAML into a local file:

curl -sS "https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.0.0/docs/examples/alb-ingress-controller.yaml" > alb-ingress-controller.yaml

Edit the AWS ALB Ingress controller YAML to include the clusterName of the Kubernetes (or) Amazon EKS cluster.

Edit the –cluster-name flag to be the real name of our Kubernetes (or) Amazon EKS cluster.

Deploy the AWS ALB Ingress controller YAML:

kubectl apply -f alb-ingress-controller.yaml

Verify that the deployment was successful and the controller started:

kubectl logs -n kube-system $(kubectl get po -n kube-system | egrep -o alb-ingress[a-zA-Z0-9-]+)

You should be able to see the following output:

-------------------------------------------------------------------------------
AWS ALB Ingress controllerRelease: v1.0.0Build: git-6ee1276Repository: https://github.com/kubernetes-sigs/aws-alb-ingress-controller
-------------------------------------------------------------------------------

Deploy Sample Application

Now let’s deploy a sample 2048 game into our Kubernetes cluster and use the Ingress resource to expose it to traffic:

Deploy 2048 game resources:

kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.0.0/docs/examples/2048/2048-namespace.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.0.0/docs/examples/2048/2048-deployment.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.0.0/docs/examples/2048/2048-service.yaml

Deploy an Ingress resource for the 2048 game:

kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.0.0/docs/examples/2048/2048-ingress.yaml

After few seconds, verify that the Ingress resource is enabled:

kubectl get ingress/2048-ingress -n 2048-game

You should be able to see the following output:

NAME         HOSTS         ADDRESS         PORTS   AGE
2048-ingress   *    DNS-Name-Of-Your-ALB    80     3m

Open a browser. Copy and paste your “DNS-Name-Of-Your-ALB”. You should be to access your newly deployed 2048 game – have fun!

Get Involved

The AWS ALB Ingress controller, a subproject of Kubernetes SIG (Special Interest Group) AWS, is a fully open source project maintained by Yang Yang (@M00nf1sh) and Kraig Amador. Kubernetes SIG-AWS’s technical roadmap is currently steered by three SIG chairs: Nishi Davidson (@nishidavidson), Justin Santa Barbara, and Kris Nova (@krisnova).

AWS ALB Ingress controller has been pegged as an alpha feature in Kubernetes 1.13, due to release early December 2018. The AWS team has also tested the Ingress controller with Amazon EKS that currently supports Kubernetes version 1.10.

More resources:

  • AWS ALB Ingress Controller documentation
  • aws-alb-ingress-controller Github repo
  • Contribute to aws-alb-ingress-controller

转载于:https://www.cnblogs.com/cloudrivers/p/11231475.html

Kubernetes Ingress with AWS ALB Ingress Controller相关推荐

  1. ALB Ingress 发布,轻松应对云原生应用流量管理

    作者:元毅 审核校对:溪洋.海珠 编辑&排版:雯燕 背景 随着云原生应用微服务化.Serverless 化,用户需要面对复杂路由规则可配置.支持多种应用层协议(HTTP.HTTPS 和 QUI ...

  2. Kubernetes K8S 1.20部署Ingress nginx 0.30

    主机配置规划 服务器名称(hostname) 系统版本 配置 内网IP 外网IP(模拟) k8s-master CentOS7.7 2C/4G/20G 172.16.1.110 10.0.0.110 ...

  3. 安装 AWS Load Balancer Controller 附加组件

    背景: 区域:新加坡 创建一个 IAM policy #curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balan ...

  4. 关于AWS Alb和Route53的使用 小结

    1. 首先,关于AWS ALB的说明文档,关于Route53的说明文档. 2. Alb是个负载均衡器.如图,相对应的还有一个target groups.Alb通过listener的监听端口或者url来 ...

  5. Kubernetes NodePort vs Loadbalancer vs Ingress 在生成中如何选择?

    最近,有人问我NodePort,LoadBalancers和Ingress之间有什么区别.它们都是将外部流量带入群集的不同方法,并且它们都以不同的方式进行.简单的说,生产环境建议使用Loadbalan ...

  6. nginx upstream配置aws alb域名导致timeout报错

    目录 问题描述 问题分析 问题结论 解决方法 问题描述 先贴nginx的配置,下面是我的nginx ingress的upstream配置,将流量转发到aws的 alb  上,通过alb的负载均衡策略, ...

  7. 20-【istio】-【流量管理】-【Ingress gateway】Istio ingress gateway

    这里以istio 1.6.0为例 不同版本的istio安装步骤参考官网:Istio / Ingress Gateways 注:这里只给出相关步骤参考,在实践时,结合该博客.官网一起看. istio i ...

  8. 从Kubernetes安全地访问AWS服务,告诉你多云场景下如何管理云凭据!

    作者| Alexey Ledenev 翻译 | 天道酬勤,责编 | Carol 出品 | CSDN云计算(ID:CSDNcloud) 随着企业与各种云提供商合作,多云场景已经变得十分常见. 在谷歌Ku ...

  9. AWS ALB ELB

    How Elastic Load Balancing works - Elastic Load Balancing 使用AWS Application Load Balancer实现基于主机名的路由分 ...

最新文章

  1. c++中的auto关键字
  2. 调试JavaScript/VB Script脚本程序(IE篇)
  3. jquery form 序列化
  4. linux /etc/profile和/etc/bashrc
  5. 解决远程连接mysql很慢的方法(mysql_connect 打开连接慢)
  6. 很好的理解遗传算法的样例
  7. Redis集群之哨兵模式
  8. 关于oracle数据库的导出导出
  9. python第三方库的安装方式_Python第三方库的几种安装方式(小结)
  10. 在计算机网络中url的含义是,计算机中URL是指什么
  11. ESXi5安装vib格式驱动
  12. 大学高数常微分方程思维导图_高等数学各章节知识点框架 常微分方程.pdf
  13. python之简介及入门
  14. [UE4C++程序]GameModule与Plugin
  15. [28期] 精力有限,精神信念的力量是无限的.....
  16. python爬虫小工具——下载助手
  17. 1-乙基-3-甲基咪唑醋酸盐([EMIM][Ac]);甲基三辛基醋酸铵[N(1,8,8,8)][Ac]齐岳离子液体
  18. java获取当天星期几
  19. 超级牛逼的立体画,太厉害了!
  20. 【matplotlib】散点图详解

热门文章

  1. win10关机后cpu风扇还在转_电脑关机后cpu风扇还在转如何解决【解决方法】
  2. 局域网不能访问mysql数据库
  3. 【Delphi Frame 使用示范】
  4. All in One主机
  5. 策略专题报告:中美科技行业对比(20210107).PDF
  6. php js ie8,jquery版本几适应ie8
  7. 易到用车周航:公司消亡、平台迭起、个体放大是未来发展的方向
  8. python批量查询steam游戏价格
  9. Jmeter下TPS插件的安装步骤(转)
  10. 读书笔记|《高质量读研:教你如何写论文、做科研》 张军平