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详情请看:

相关推荐
brzhang12 小时前
读懂 MiniMax Agent 的设计逻辑,然后我复刻了一个MiniMax Agent
前端·后端·架构
草明12 小时前
Go 的 IO 多路复用
开发语言·后端·golang
蓝-萧13 小时前
Plugin ‘mysql_native_password‘ is not loaded`
java·后端
故事不长丨13 小时前
【Java SpringBoot+Vue 实现视频文件上传与存储】
java·javascript·spring boot·vscode·后端·vue·intellij-idea
9ilk13 小时前
【仿RabbitMQ的发布订阅式消息队列】--- 前置技术
分布式·后端·中间件·rabbitmq
鬼火儿14 小时前
Golang笔记——Interface类型
java·后端
三十_A14 小时前
【无标题】
前端·后端·node.js
蓝-萧14 小时前
Redis——Windows安装
java·后端
王元_SmallA15 小时前
【玩转全栈】----Django基本配置和介绍
java·后端
Moonbit15 小时前
招募进行时 | MoonBit AI : 程序语言 & 大模型
前端·后端·面试