惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
博客园 - 司徒正美
美团技术团队
Martin Fowler
Martin Fowler
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
Vercel News
Vercel News
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
U
Unit 42
Y
Y Combinator Blog
月光博客
月光博客
Hugging Face - Blog
Hugging Face - Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
GbyAI
GbyAI
H
Help Net Security
量子位
Last Week in AI
Last Week in AI
博客园_首页
腾讯CDC
小众软件
小众软件

二丫讲梵

学习周刊-总第258期-2026年第15周 学习周刊-总第257期-2026年第14周 学习周刊-总第256期-2026年第13周 学习周刊-总第255期-2026年第12周 学习周刊-总第254期-2026年第11周 学习周刊-总第253期-2026年第10周 临时插播一条羊毛,免费领取450元大模型API代金券 学习周刊-总第252期-2026年第09周 学习周刊-总第251期-2026年第08周 学习周刊-总第250期-2026年第07周 学习周刊-总第249期-2026年第06周 诚邀评论,聊聊你所知欲知的我 学习周刊-总第248期-2026年第05周 我的QQ动态之2015年 我的QQ动态之2014年 我的QQ动态之2013年 我的QQ动态之2012年 我的QQ动态-2010-2011年 我的QQ动态-创栏小叙 学习周刊-总第247期-2026年第04周 Nexus社区版权益阉割--一文告诉你有哪些版本可以选择 学习周刊-总第246期-2026年第03周 学习周刊-总第245期-2026年第02周 学习周刊-总第244期-2026年第01周 学习周刊-总第243期-2025年第52周 学习周刊-总第242期-2025年第51周 开源项目ZenOps:带你领略禅意运维 学习周刊-总第241期-2025年第50周 用京东金融,享负债人生 学习周刊-总第240期-2025年第49周
AWS运维部署实践--给EKS集群安装Ingress-Controller
二丫讲梵 · 2024-10-23 · via 二丫讲梵

集群创建完毕之后,可以正常部署应用,但是要想被外部访问,还需要配置 ingress-controller。接下来介绍一下配置的流程。

# 创建 OIDC

注意指定 集群名字

$ oidc_id=$(aws eks describe-cluster --name aws3-sgp-eks-cluster --query "cluster.identity.oidc.issuer" --output text | cut -d '/' -f 5)
$ echo $oidc_id
$ aws iam list-open-id-connect-providers | grep $oidc_id | cut -d "/" -f4
$ eksctl utils associate-iam-oidc-provider --cluster aws3-sgp-eks-cluster --approve

1
2
3
4

创建成功之后,可以在 IAM 的角色提供商那里可以看到。

img

# OIDC 关联角色

先创建策略:

$ curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.8.1/docs/install/iam_policy.json


$ aws iam create-policy \
   --policy-name AWSLoadBalancerControllerIAMPolicxh \
   --policy-document file://iam_policy.json

# 执行之后会输出策略内容。

1
2
3
4
5
6
7
8

然后使用 eksctl 创建角色

 # 注意arn使用上一部 oidc生成的
 eksctl create iamserviceaccount \
    --cluster=aws3-sgp-eks-cluster \
    --namespace=kube-system \
    --name=aws-load-balancer-controller \
    --role-name AmazonEKSLoadBalancerControllerRole \
    --attach-policy-arn=arn:aws:iam::0000007:policy/AWSLoadBalancerControllerIAMPolicxh \
  --approve

1
2
3
4
5
6
7
8

📢 特别注意

这里踩坑了,创建的时候,总是会提示:

image-20240718145420060

这里实际 kubectl get sa -n kube-system | grep load,以及查看都找不到这个信息,猜测是 eksctl 的 bug。

那么可以将 --name=aws-load-balancer-controller 改为 --name=aws-load-balancer-controller-new,但需要注意下边安装 controller 时把名字指定为与这里一致。

如果正常创建了,可以查看一下这个 sa:

$ k get sa -n kube-system aws-load-balancer-controller-new -oyaml

apiVersion: v1
kind: ServiceAccount
metadata:
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::0000007:role/AmazonEKSLoadBalancerControllerRoleg
  creationTimestamp: "2024-07-17T09:59:06Z"
  labels:
    app.kubernetes.io/managed-by: eksctl
  name: aws-load-balancer-controller
  namespace: kube-system
  resourceVersion: "45191"
  uid: 0755f65b-7886-4e38-b022-4729b147e2bb

1
2
3
4
5
6
7
8
9
10
11
12
13
14

其中的 arn 可以在控制台的 IAM 中查看到这个角色,以及角色里边关联的策略。

# 添加 helm 源

$ helm repo add eks https://aws.github.io/eks-charts
$ helm repo update eks

1
2

# 安装 ingress-controller

$ helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
  -n kube-system \
  --set clusterName=aws3-sgp-eks-cluster \
  --set serviceAccount.create=false \
  --set serviceAccount.name=aws-load-balancer-controller

1
2
3
4
5

注意这里的角色与上边保持一致。默认情况下,安装的副本数为 2,如果你是生产环境,可酌情考虑增加。

然后查看这个 deployment:

$ k get deploy -n kube-system aws-load-balancer-controller
NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
aws-load-balancer-controller   2/2     2            2           20h

1
2
3

至此,一个基础的集群,以及基本的 ingress-controller 就部署好了。

如果在部署之后,状态不正常,然后可以通过查看日志来分析:

$ k logs -f -n kube-system  aws-load-balancer-controller-64bb9f5f57-r5tfh

{"level":"info","ts":"2024-10-22T01:32:23Z","msg":"version","GitVersion":"v2.9.1","GitCommit":"e0f59c6c35f44b42f5eeae514059b356f9ba4ee7","BuildDate":"2024-10-11T23:16:28+0000"}
{"level":"error","ts":"2024-10-22T01:32:28Z","logger":"setup","msg":"unable to initialize AWS cloud","error":"failed to get VPC ID: failed to fetch VPC ID from instance metadata: error in fetching vpc id through ec2 metadata: get mac metadata: operation error ec2imds: GetMetadata, canceled, context deadline exceeded"}

1
2
3
4

如果遇到如上错误,则可通过在安装时指定区域以及 VPC 来解决。详见:issue (opens new window)

$ helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
-n kube-system \
--set clusterName=aws3-sgp-eks-cluster \
--set serviceAccount.create=false \
--set serviceAccount.name=aws-load-balancer-controller
--set region=ap-southeast-1   \
--set vpcId=vpc-xxxxxxxxxxxxxx

1
2
3
4
5
6
7

安装成功之后,剩下的就是部署应用,以及配置 ingress 了。后边单独开篇来介绍。

参考文档: