AWS EKS 计算资源自动扩缩之按需申请Fargate[AWS 中国宁夏区]

设置Fargate

创建Amazon EKS Pod execution IAM role

fargate正常运行需要有Amazon EKS Pod execution IAM role,详情可以参考Amazon EKS Pod execution IAM role

编辑policy内容,并保存为pod-execution-role-trust-policy.json,其中region-codeaws-account需要填你真实的内容

json 复制代码
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Condition": {
         "ArnLike": {
            "aws:SourceArn": "arn:aws-cn:eks:<region-code>:<aws-account>:fargateprofile/*"
         }
      },
      "Principal": {
        "Service": "eks-fargate-pods.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

创建role,名称可以自定义,我设置为AmazonEKSFargatePodExecutionRole

css 复制代码
aws iam create-role --role-name AmazonEKSFargatePodExecutionRole  --assume-role-policy-document file://"pod-execution-role-trust-policy.json"

AmazonEKSFargatePodExecutionRoleAmazonEKSFargatePodExecutionRolePolicy关联

arduino 复制代码
aws iam attach-role-policy --policy-arn arn:aws-cn:iam::aws:policy/AmazonEKSFargatePodExecutionRolePolicy --role-name AmazonEKSFargatePodExecutionRole

创建fargate profile

填写自己的fargate-profile名称,并选定刚才创建的AmazonEKSFargatePodExecutionRole 为这个profie填入合适的namespace设置,详情见AWS Fargate profile 检查并创建 创建需要几分钟 创建完成

测试fargate的使用

这里是一个简单的nginx deployment样例,请注意它的namesapce必须要和fargate proflie中的namespace设置相匹配 ,匹配规则为AWS Fargate profile

yaml 复制代码
apiVersion: apps/v1
kind: Deployment
metadata:
  name: eks-sample-linux-deployment
  # 必须和fargate proflie中的namespace设置相匹配,https://docs.aws.amazon.com/eks/latest/userguide/fargate-profile.html
  namespace: prod-fargate
  labels:
    app: eks-sample-linux-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: eks-sample-linux-app
  template:
    metadata:
      labels:
        app: eks-sample-linux-app
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: kubernetes.io/arch
                    operator: In
                    values:
                      - amd64
                      - arm64
      containers:
        - name: nginx
          image: public.ecr.aws/nginx/nginx:1.23
          ports:
            - name: http
              containerPort: 80
          imagePullPolicy: IfNotPresent
      nodeSelector:
        kubernetes.io/os: linux

等待片刻我们发现fargate作为底层计算资源已经运行了正确的nginx

fargate和ec2 node group不一样,只需要你设置好pod的HPA后,pod就可以自动的水平扩展并及时获取对应的fargate计算资源,不再需要autosacler等插件。

关于fargate详情请看:

相关推荐
一灯架构6 小时前
90%的人答错!一文带你彻底搞懂ArrayList
java·后端
mldong7 小时前
Python开发者狂喜!200+课时FastAPI全栈实战合集,10大模块持续更新中🔥
后端
GreenTea8 小时前
从 Claw-Code 看 AI 驱动的大型项目开发:2 人 + 10 个自治 Agent 如何产出 48K 行 Rust 代码
前端·人工智能·后端
Moment10 小时前
AI 全栈指南:NestJs 中的 Service Provider 和 Module
前端·后端·面试
IT_陈寒10 小时前
为什么我的JavaScript异步回调总是乱序执行?
前端·人工智能·后端
Moment10 小时前
AI全栈入门指南:NestJs 中的 DTO 和数据校验
前端·后端·面试
小村儿10 小时前
Harness Engineering:为什么你用 AI 越用越累?
前端·后端·ai编程
亚马逊云开发者10 小时前
Claude Code Token费用暴涨3倍?SageMaker+LiteLLM动态路由方案帮你省70%
aws
小码哥_常11 小时前
为什么PUT和DELETE请求在大公司中逐渐被弃用?
后端
亚马逊云开发者11 小时前
文搜视频、图搜视频、视频搜视频——Nova Multimodal Embeddings 多模态素材搜索实战
aws