创建集群后,如何排查 Amazon EKS 环境中的错误?
上次更新日期:2022 年 7 月 14 日
创建集群后,我的 Amazon Elastic Kubernetes Service(Amazon EKS)环境中出现错误。
简短描述
您可以使用 AWSPremiumSupport-TroubleshootEKSCluster 自动化工作流,排查 Amazon EKS 环境中的常见错误。此工作流会提供详细报告,列出错误、警告以及 Amazon Web Services(AWS)推荐的最佳实践的链接。
注意:要使用 AWSPremiumSupport-TroubleshootEKSCluster 自动化工作流,您必须订阅企业或业务支持计划。
如果遇到以下问题,您可以使用 AWSPremiumSupport-TroubleshootEKSCluster 自动化工作流:
- 您的 Kubernetes Cluster Autoscaler 无法正常工作。
- 您的内部负载均衡器无法在私有或公有子网中创建。
- 您不清楚 Worker 节点是否正在使用最新的 Amazon 机器映像(AMI)。
- 您的 aws-node 容器组(pod)中出现访问被拒的错误。
- 您无法拉取 Amazon Elastic Container Registry(Amazon ECR)映像。
- 您的托管节点不稳定,或者您的自行管理节点没有加入集群。
AWSPremiumSupport-TroubleshootEKSCluster 自动化工作流会进行以下检查:
- 检查自动扩缩组的 Cluster AutoScaler 子网标签,此标签用于内部及面向互联网的负载均衡器与 Worker 安全组。
重要提示:如果您有多个安全组与 Worker 节点相关联,必须将标签应用于其中一个安全组。 将标签的键设置为 kubernetes.io/cluster/your-cluster-name。将值设置为 owned。如果您只有一个安全组与 Worker 节点相关联,则此标签是可选的。 - 检查工件节点以获取最新的 AMI。
- 检查安全组规则以获取最低设置和推荐设置。例如,工作流会检查来自集群的安全组(即所有连接到集群的安全组)和工件安全组的入口与出口。
- 检查自定义网络访问控制列表(网络 ACL)配置。
- 检查 Worker 节点上的 AWS Identity and Access Management(IAM)策略,包括 AmazonEKSWorkerNodePolicy 和 AmazonEC2ContainerRegistryReadOnly 策略。
- 通过检查 Worker 节点所在子网的路由表,检查 Worker 节点是否可以连接到互联网。
解决方法
使您的工件节点可被发现
要使您的工件节点可被发现,请使用 AWSPremiumSupport-TroubleshootEKSCluster 自动化工作流和您的 Amazon EKS 集群:
1. 打开 Amazon EC2 控制台。
2. 在导航窗格中,选择 Instances(实例)。
3. 为您的 Worker 节点选择 Amazon Elastic Compute Cloud(Amazon EC2)实例,然后选择 Tags(标签)选项卡。
4. 选择 Add/Edit Tags(添加/编辑标签)。
5. 对于 Key(键),请输入 kubernetes.io/cluster/your-cluster-name。对于 Value(值),请输入 'owned'/ 'shared'。
6. 选择 Save(保存)。
AWSPremiumSupport-TroubleshootEKSCluster 自动化工作流使用以下策略运行。此策略必须包括访问集群的最低权限。该集群只能通过 AutomationAssumeRole 进行访问。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AWSPremiumSupportTroubleshootEKSCluster",
"Effect": "Allow",
"Action": [
"eks:ListNodegroups",
"eks:DescribeCluster",
"eks:DescribeNodegroup",
"iam:GetInstanceProfile",
"iam:ListInstanceProfiles",
"iam:ListAttachedRolePolicies",
"autoscaling:DescribeAutoScalingGroups",
"ec2:DescribeInstanceTypes",
"ec2:DescribeInstances",
"ec2:DescribeNatGateways",
"ec2:DescribeSecurityGroups",
"ec2:DescribeVpcs",
"ec2:DescribeSubnets",
"ec2:DescribeNetworkAcls",
"ec2:DescribeRouteTables"
],
"Resource": "*"
},
{
"Sid": "GetPublicSSMParams",
"Effect": "Allow",
"Action": "ssm:GetParameter",
"Resource": [
"arn:aws:ssm:*:*:parameter/aws/service/eks/optimized-ami/*/amazon-linux-2/recommended/image_id",
"arn:aws:ssm:*:*:parameter/aws/service/ami-windows-latest/Windows_Server-2019-English-Core-EKS_Optimized-*/image_id",
"arn:aws:ssm:*:*:parameter/aws/service/ami-windows-latest/Windows_Server-2019-English-Full-EKS_Optimized-*/image_id",
"arn:aws:ssm:*:*:parameter/aws/service/ami-windows-latest/Windows_Server-1909-English-Core-EKS_Optimized-*/image_id",
"arn:aws:ssm:*:*:parameter/aws/service/eks/optimized-ami/*/amazon-linux-2-gpu/recommended/image_id"
]
},
{
"Sid": "UploadObjectToS3",
"Effect": "Allow",
"Action": [
"s3:GetBucketPolicyStatus",
"s3:GetBucketAcl",
"s3:PutObject"
],
"Resource": [
"<BUCKET_ARN>",
"<BUCKET_ARN>/AWSPremiumSupport-TroubleshootEKSCluster-*"
]
}
]
}
从 AWS Systems Manager 控制台运行自动化工作流
1. 打开 Systems Manager 控制台。
2. 在导航窗格中,选择 Automation(自动化)。
注意:如果 Systems Manager 主页先打开,则选择菜单图标打开导航窗格,然后选择 Automation(自动化)。
3. 选择 Execute automation(执行自动化)。
4. 在 Automation document(自动化文档)搜索框中,输入 AWSPremiumSupport-TroubleshootEKSCluster,然后按 Enter 键。
5. 从搜索结果中,选择 AWSPremiumSupport-TroubleshootEKSCluster。
注意:文档拥有者为 Amazon。
6. 在 Document description(文档描述)选项卡中,验证 Document version(文档版本)是否设置为 Default version at runtime(运行时默认版本)。
7. 选择 Next(下一步)。
8. 在 Execute automation document(执行自动化文档)部分,选择 Simple execution(简单执行)。
9. 在 Input parameters(输入参数)部分,指定以下参数:
将 ClusterName 设置为集群的名称。此集群必须在您的 AWS 账户中运行。
将 AutomationAssumeRole 设置为要用于工作流的 IAM 角色。
(可选)如果需要,将 BucketName 设置到要上传报告的 Amazon Simple Storage Service(Amazon S3)存储桶。
注意:如果要指定 AutomationAssumeRole,请创建适用于该策略的 IAM 角色和 S3 存储桶。然后,将报告上传到您自己的 S3 存储桶(BucketName)以实现 SSM 自动化。
10. 选择 Execute(执行)。
11. 要监控运行进度,请选择正在运行的 Automation(自动化),然后选择 Steps(步骤)选项卡。
12. 该过程完成后,选择 Descriptions(描述)选项卡,然后选择 View output(查看输出)以查看结果。
注意:结果显示为一份报告,其中列出了集群的所有错误和警告。
从 AWS CLI 运行自动化工作流
注意:如果您在运行 AWS 命令行界面(AWS CLI)命令时遇到错误,请确保您使用的是最新版本的 AWS CLI。如果您想指定 AutomationAssumeRole 并将报告上传到您自己的 S3 存储桶(S3BucketName)以运行自动化工作流,请创建适用于该策略的 IAM 角色和 S3 存储桶。
如果要将报告放在 S3 存储桶中,请运行以下命令:
aws ssm start-automation-execution --document-name "AWSPremiumSupport-TroubleshootEKSCluster" --document-version "\$DEFAULT" --parameters '{"ClusterName":["your-eks-cluster"],"AutomationAssumeRole":["arn:aws:iam::123456789012:role/eks-troubleshooter-role"],"S3BucketName":["your_bucket"]}' --region your_region
如果不想将报告上传到 S3 存储桶,请运行以下命令:
aws ssm start-automation-execution --document-name "AWSPremiumSupport-TroubleshootEKSCluster" --document-version "\$DEFAULT" --parameters '{"ClusterName":["your-eks-cluster"],"AutomationAssumeRole":["arn:aws:iam::123456789012:role/eks-troubleshooter-role"]}' --region your_region