AWS CLI创建Amazon EKS服务

这篇具有很好参考价值的文章主要介绍了AWS CLI创建Amazon EKS服务。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Amazon EKS文档

前言:
创建ClusterRole需要选择一下的角色
AmazonEKSClusterPolicy

创建NodeRole需要选择一下的角色
AmazonEC2ContainerRegistryReadOnly
AmazonEKSWorkerNodePolicy
AmazonEKS_CNI_Policy

1、创建 Amazon EKS 集群 IAM 角色
1)创建json

[root@ip-172-93-1-18 ~]# cat example-policy.json 
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ec2:Describe*",
        "iam:ListRoles",
        "sts:AssumeRole"
      ],
      "Resource": "*"
    }
  ]
}
[root@ip-172-93-1-18 ~]# cat >eks-cluster-role-trust-policy.json <<EOF
> {
>   "Version": "2012-10-17",
>   "Statement": [
>     {
>       "Effect": "Allow",
>       "Principal": {
>         "Service": "eks.amazonaws.com"
>       },
>       "Action": "sts:AssumeRole"
>     }
>   ]
> }
> EOF

2)创建 Amazon EKS 集群 IAM 角色

[root@ip-172-93-1-18 ~]# aws iam create-role --role-name GamefiAmazonEKSClusterRole --assume-role-policy-document file://"eks-cluster-role-trust-policy.json"
{
    "Role": {
        "AssumeRolePolicyDocument": {
            "Version": "2012-10-17", 
            "Statement": [
                {
                    "Action": "sts:AssumeRole", 
                    "Effect": "Allow", 
                    "Principal": {
                        "Service": "eks.amazonaws.com"
                    }
                }
            ]
        }, 
        "RoleId": "AROA3BR37RVO4B2BN3IEW", 
        "CreateDate": "2022-10-21T07:49:13Z", 
        "RoleName": "GamefiAmazonEKSClusterRole", 
        "Path": "/", 
        "Arn": "arn:aws:iam::0123456789:role/GamefiAmazonEKSClusterRole"
    }
}

3)将名为 GamefiAmazonEKSClusterRole的 Amazon EKS 托管 IAM policy 附加到角色

[root@ip-172-93-1-18 ~]# aws iam attach-role-policy --policy-arn arn:aws:iam::aws:policy/AmazonEKSClusterPolicy --role-name GamefiAmazonEKSClusterRole

2、创建 Amazon EKS 集群

[root@ip-172-93-1-18 ~]# eksctl create cluster --name gamefi-cluster --region ap-east-1 --version 1.23 --vpc-public-subnets subnet-0670a45dccf9fad59,subnet-0996714ab4116d6e6,subnet-07d5b48efd70ae503 --without-nodegroup
2022-10-21 07:55:26 []  eksctl version 0.115.0
2022-10-21 07:55:26 []  using region ap-east-1
Error: could not import subnet subnet-07d5b48efd70ae503: subnet ID "subnet-0996714ab4116d6e6" is not the same as "subnet-07d5b48efd70ae503"
[root@ip-172-93-1-18 ~]# eksctl create cluster --name gamefi-cluster --region ap-east-1 --version 1.23 --vpc-public-subnets subnet-0670a45dccf9fad59,subnet-0996714ab4116d6e6 --without-nodegroup
2022-10-21 07:57:16 []  eksctl version 0.115.0
2022-10-21 07:57:16 []  using region ap-east-1
2022-10-21 07:57:16 []  using existing VPC (vpc-09197fd1833f76a27) and subnets (private:map[] public:map[ap-east-1a:{subnet-0996714ab4116d6e6 ap-east-1a 172.93.5.0/24 0 } ap-east-1b:{subnet-0670a45dccf9fad59 ap-east-1b 172.93.6.0/24 0 }])
2022-10-21 07:57:16 [!]  custom VPC/subnets will be used; if resulting cluster doesn't function as expected, make sure to review the configuration of VPC/subnets
2022-10-21 07:57:16 []  using Kubernetes version 1.23
2022-10-21 07:57:16 []  creating EKS cluster "gamefi-cluster" in "ap-east-1" region with 
2022-10-21 07:57:16 []  if you encounter any issues, check CloudFormation console or try 'eksctl utils describe-stacks --region=ap-east-1 --cluster=gamefi-cluster'
2022-10-21 07:57:16 []  Kubernetes API endpoint access will use default of {publicAccess=true, privateAccess=false} for cluster "gamefi-cluster" in "ap-east-1"
2022-10-21 07:57:16 []  CloudWatch logging will not be enabled for cluster "gamefi-cluster" in "ap-east-1"
2022-10-21 07:57:16 []  you can enable it with 'eksctl utils update-cluster-logging --enable-types={SPECIFY-YOUR-LOG-TYPES-HERE (e.g. all)} --region=ap-east-1 --cluster=gamefi-cluster'
2022-10-21 07:57:16 []  
2 sequential tasks: { create cluster control plane "gamefi-cluster", wait for control plane to become ready 
}
2022-10-21 07:57:16 []  building cluster stack "eksctl-gamefi-cluster-cluster"
2022-10-21 07:57:16 []  deploying stack "eksctl-gamefi-cluster-cluster"
2022-10-21 07:57:46 []  waiting for CloudFormation stack "eksctl-gamefi-cluster-cluster"
2022-10-21 07:58:16 []  waiting for CloudFormation stack "eksctl-gamefi-cluster-cluster"
2022-10-21 07:59:17 []  waiting for CloudFormation stack "eksctl-gamefi-cluster-cluster"
2022-10-21 08:00:17 []  waiting for CloudFormation stack "eksctl-gamefi-cluster-cluster"
2022-10-21 08:01:17 []  waiting for CloudFormation stack "eksctl-gamefi-cluster-cluster"
2022-10-21 08:02:17 []  waiting for CloudFormation stack "eksctl-gamefi-cluster-cluster"
2022-10-21 08:03:17 []  waiting for CloudFormation stack "eksctl-gamefi-cluster-cluster"
2022-10-21 08:04:17 []  waiting for CloudFormation stack "eksctl-gamefi-cluster-cluster"
2022-10-21 08:05:17 []  waiting for CloudFormation stack "eksctl-gamefi-cluster-cluster"
2022-10-21 08:06:17 []  waiting for CloudFormation stack "eksctl-gamefi-cluster-cluster"
2022-10-21 08:07:17 []  waiting for CloudFormation stack "eksctl-gamefi-cluster-cluster"
2022-10-21 08:09:17 []  waiting for the control plane to become ready
2022-10-21 08:09:17 [!]  failed to determine authenticator version, leaving API version as default v1alpha1: failed to parse versions: unable to parse first version "": strconv.ParseUint: parsing "": invalid syntax
2022-10-21 08:09:18 []  saved kubeconfig as "/root/.kube/config"
2022-10-21 08:09:18 []  no tasks
2022-10-21 08:09:18 []  all EKS cluster resources for "gamefi-cluster" have been created
2022-10-21 08:09:18 []  kubectl command should work with "/root/.kube/config", try 'kubectl get nodes'
2022-10-21 08:09:18 []  EKS cluster "gamefi-cluster" in "ap-east-1" region is ready

集群预配置需要几分钟时间。在创建集群时,将显示几行输出。输出的最后一行类似于以下示例行。

[]  EKS cluster "my-cluster" in "region-code" region is ready

在控制台上查看EKS集群
AWS CLI创建Amazon EKS服务

3、与EKS建立通信

[root@ip-172-93-1-18 ~]# aws eks update-kubeconfig --region ap-east-1 --name gamefi-cluster
Added new context arn:aws:eks:ap-east-1:0123456789:cluster/gamefi-cluster to /root/.kube/config

通过运行以下命令以确认与集群的通信。

[root@ip-172-93-1-18 ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.100.0.1   <none>        443/TCP   8m52s

4、创建vpc-cni角色
创建 IAM 角色。您可以使用 eksctl 或 kubectl 和 AWS CLI 以创建 IAM 角色

[root@ip-172-93-1-18 ~]# aws eks describe-cluster --name gamefi-cluster --query "cluster.identity.oidc.issuer" --output text
https://oidc.eks.ap-east-1.amazonaws.com/id/876ADBC8677BE9381336CAE6FAE83F1E

创建文件

[root@ip-172-93-1-18 ~]# vim vpc-cni-trust-policy.json
[root@ip-172-93-1-18 ~]# cat vpc-cni-trust-policy.json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Federated": "arn:aws:iam::0123456789:oidc-provider/oidc.eks.region-code.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE"
            },
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Condition": {
                "StringEquals": {
                    "oidc.eks.region-code.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:aud": "sts.amazonaws.com",
                    "oidc.eks.region-code.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:sub": "system:serviceaccount:kube-system:aws-node"
                }
            }
        }
    ]
}

创建GameFiAmazonEKSVPCCNIRole角色

[root@ip-172-93-1-18 ~]# aws iam create-role --role-name GameFiAmazonEKSVPCCNIRole   --assume-role-policy-document file://"vpc-cni-trust-policy.json"
{
    "Role": {
        "AssumeRolePolicyDocument": {
            "Version": "2012-10-17", 
            "Statement": [
                {
                    "Action": "sts:AssumeRoleWithWebIdentity", 
                    "Effect": "Allow", 
                    "Condition": {
                        "StringEquals": {
                            "oidc.eks.region-code.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:sub": "system:serviceaccount:kube-system:aws-node", 
                            "oidc.eks.region-code.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:aud": "sts.amazonaws.com"
                        }
                    }, 
                    "Principal": {
                        "Federated": "arn:aws:iam::0123456789:oidc-provider/oidc.eks.region-code.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE"
                    }
                }
            ]
        }, 
        "RoleId": "AROA3BR37RVOUO3DSXZOW", 
        "CreateDate": "2022-10-21T08:35:11Z", 
        "RoleName": "GameFiAmazonEKSVPCCNIRole", 
        "Path": "/", 
        "Arn": "arn:aws:iam::0123456789:role/GameFiAmazonEKSVPCCNIRole"
    }
}

将所需的 IAM policy 附加到角色。运行与集群的 IP 系列匹配的命令。

[root@ip-172-93-1-18 ~]# aws iam attach-role-policy --policy-arn arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy --role-name GameFiAmazonEKSVPCCNIRole

运行以下命令以使用您以前创建的 IAM 角色的 ARN 对 aws-node 服务账户添加注释

[root@ip-172-93-1-18 ~]# kubectl annotate serviceaccount -n kube-system aws-node eks.amazonaws.com/role-arn=arn:aws:iam::0123456789:role/GameFiAmazonEKSVPCCNIRole
serviceaccount/aws-node annotated

5、创建group

[root@ip-172-93-1-18 ~]# eksctl create nodegroup --cluster gamefi-cluster --region ap-east-1 --name gamefi-groups --node-type t3.medium --nodes 2 --nodes-min 2 --nodes-max 3 --ssh-access --ssh-public-key aitd-prod.pem
2022-10-21 10:16:35 [?]  will use version 1.23 for new nodegroup(s) based on control plane version
2022-10-21 10:16:36 [?]  nodegroup "gamefi-groups" will use "" [AmazonLinux2/1.23]
2022-10-21 10:16:36 [?]  using EC2 key pair %!q(*string=<nil>)
2022-10-21 10:16:36 [?]  1 existing nodegroup(s) (gamefi-group) will be excluded
2022-10-21 10:16:36 [?]  1 nodegroup (gamefi-groups) was included (based on the include/exclude rules)
2022-10-21 10:16:36 [?]  will create a CloudFormation stack for each of 1 managed nodegroups in cluster "gamefi-cluster"
2022-10-21 10:16:37 [?]  
2 sequential tasks: { fix cluster compatibility, 1 task: { 1 task: { create managed nodegroup "gamefi-groups" } } 
}
2022-10-21 10:16:37 [?]  checking cluster stack for missing resources
2022-10-21 10:16:37 [?]  cluster stack has all required resources
2022-10-21 10:16:37 [?]  building managed nodegroup stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:16:37 [?]  deploying stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:16:37 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:17:07 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:17:44 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:18:29 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:20:04 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:20:37 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:21:45 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:23:15 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:24:24 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:24:59 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:25:57 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:27:41 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:28:50 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:30:33 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:31:16 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:32:52 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:33:51 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:34:43 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:36:43 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:37:22 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:39:18 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:40:55 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:41:07 [?]  waiting for CloudFormation stack "eksctl-gamefi-cluster-nodegroup-gamefi-groups"
2022-10-21 10:41:07 [?]  1 error(s) occurred and nodegroups haven't been created properly, you may wish to check CloudFormation console
2022-10-21 10:41:07 [?]  to cleanup resources, run 'eksctl delete nodegroup --region=ap-east-1 --cluster=gamefi-cluster --name=<name>' for each of the failed nodegroup
2022-10-21 10:41:07 [?]  exceeded max wait time for StackCreateComplete waiter
Error: failed to create nodegroups for cluster "gamefi-cluster"


切换到CloudFormation观察创建
https://console.aws.amazon.com/cloudformation/home
AWS CLI创建Amazon EKS服务
6、先测试AWS CLi配置运行正常

[root@ip-172-93-1-18 ~]# aws sts get-caller-identity
{
    "Account": "123456789", 
    "UserId": "SDA3SFERFAFDOY6WO", 
    "Arn": "arn:aws:iam::123456789:user/test"

然后#更新config文件

[root@ip-172-93-1-18 ~]# aws eks --region ap-east-1 update-kubeconfig --name gamefi-cluster
Added new context arn:aws:eks:ap-east-1:123456789:cluster/gamefi-cluster to /root/.kube/config

7、运行以下命令连接 AWS EKS文章来源地址https://www.toymoban.com/news/detail-501973.html

[root@ip-172-93-1-18 ~]# kubectl get nodes
NAME                                         STATUS   ROLES    AGE     VERSION
ip-172-93-5-25.ap-east-1.compute.internal    Ready    <none>   3m51s   v1.23.9-eks-ba74326
ip-172-93-6-207.ap-east-1.compute.internal   Ready    <none>   3m53s   v1.23.9-eks-ba74326
[root@ip-172-93-1-18 ~]# kubectl get pods -n kube-system
NAME                       READY   STATUS    RESTARTS   AGE
aws-node-6ns6x             1/1     Running   0          4m8s
aws-node-6q8ww             1/1     Running   0          4m7s
coredns-6c684977f7-sv29g   1/1     Running   0          7m40s
coredns-6c684977f7-wr54r   1/1     Running   0          7m40s
kube-proxy-cl9zl           1/1     Running   0          4m8s
kube-proxy-sw6cf           1/1     Running   0          4m7s
[root@ip-172-93-1-18 ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.100.0.1   <none>        443/TCP   18m

到了这里,关于AWS CLI创建Amazon EKS服务的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 国区AWS上传本地文件创建私有AMI镜像(无需aws cli)

    一、制作本地镜像文件-VMDK 1、使用VMware或者ESXI,用自己的镜像创建虚拟机 该虚拟机的CPU和内存随意设定,后续在AWS上可以修改,硬盘只需要挂载一块系统盘,创建硬盘时的容量是AWS上拉起实例时的最小硬盘容量 2、保证虚拟机是DHCP获取IP 查看网卡信息,保证虚拟机能正常获

    2024年02月06日
    浏览(33)
  • 【Terraform学习】使用 Terraform 创建Amazon VPC(Terraform-AWS最佳实战学习)

    前提条件 安装 Terraform : 地址 下载仓库代码模版 本实验代码 位于  task_vpc  文件夹中 。 变量文件  variables.tf   在上面的代码中,您将 声明 , aws_access_key , aws_secret_key 和  区域变量 。 terraform.tfvar    在上面的代码中,您将 定义变量的值 。 main.tf     在上面的代码中,

    2024年02月11日
    浏览(33)
  • [ 云计算 | AWS 实践 ] 基于 Amazon S3 协议搭建个人云存储服务

    本文收录于【#云计算入门与实践 - AWS】专栏中,收录 AWS 入门与实践相关博文。 本文同步于个人公众号:【 云计算洞察 】 更多关于云计算技术内容敬请关注:CSDN【#云计算入门与实践 - AWS】专栏。 本系列已更新博文: [ 云计算 | AWS 实践 ] Java 应用中使用 Amazon S3 进行存储桶

    2024年02月05日
    浏览(33)
  • 在 Amazon EKS 上部署生成式 AI 模型

    导言 生成式 AI 正在改变企业的运作方式,并加快创新的步伐。总体而言,人工智能正在改变企业利用技术的方式。生成式 AI 技术包括微调和部署大型语言模型(LLM),并允许开发人员访问这些模型以执行提示和对话。负责在 Kubernetes 上制定标准的平台团队可以在 Amazon EKS 上

    2024年02月22日
    浏览(23)
  • [ 云计算 | AWS ] 对比分析:Amazon SNS 与 SQS 消息服务的异同与选择

    AWS 提供许多出色的消息传递服务。他们最著名的两项服务是 Amazon Simple Notification Service (SNS) 和 Amazon Simple Queue Service (SQS)。虽然两者的使用方式非常相似,但它们是完全不同的服务。 这篇博文将向您解释相同点、不同点以及如何选择哪种服务。最后,我将向您展示一些示例用

    2024年02月04日
    浏览(41)
  • 使用 Python 和 AWS Boto3 更新 Amazon ECS 服务的启动命令

    在使用 Amazon Elastic Container Service (ECS) 部署容器化应用程序时,有时需要更新服务的启动命令。例如,您可能需要更改应用程序连接的数据库地址或其他配置参数。在本文中,我们将介绍如何使用 Python 和 AWS Boto3 库编写一个脚本,自动遍历 ECS 集群中的所有服务,并更新它们的任务定

    2024年03月26日
    浏览(76)
  • AWS eks 用户授权

    背景: 国内使用阿里云惯了,点点就可以完成大部分的工作,国外的AWS 大都是命令行操作,且权限设置的特别细,在创建集群后,给用户授权的工作中走了很多弯路,特记录一下。 前置条件: 1. 安装aws cli 、eksctl 命令行工具 1. 把用户与k8s 中的Group组做映射 2.生成kubeconfig

    2024年02月07日
    浏览(16)
  • ModaHub魔搭社区:基于 Amazon EKS 搭建开源向量数据库 Milvus

    目录 01 前言 02 架构说明 03 先决条件 04 创建 EKS 集群 05 部署 Milvus

    2024年02月12日
    浏览(34)
  • 玩转aws之(一)eks集群部署

    目录 1. 前言 2. 创建EKS集群 2.2.1 创建集群角色 2.2.2 创建 EKS 集群 2.2.3 添加主机组 3. 配置kubectl访问集群 3.1 安装kubectl 3.2 使用AWS CLi配置.kube/config 4. 安装ingress controll 创建集群文档参考:创建 Amazon EKS 集群 - Amazon EKS aws官方用户指南中关于创建EKS集群部分,看了几次才理解了整

    2024年01月21日
    浏览(53)
  • AWS EKS 集群自动扩容 Cluster Autoscaler

    Amazon EKS 是托管的 Kubernetes 服务,可以使用 HPA 和 Cluster Autoscaler 来在集群中实现弹性伸缩,以满足应用程序的需求并节省资源成本。 Kubernetes(K8s)提供了自动伸缩机制,旨在根据应用程序负载和资源需求的变化自动调整应用的副本数量或节点数量,以满足性能需求和优化资

    2024年02月12日
    浏览(23)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包