Creating an Amazon EKS cluster
This topic provides an overview of the available options and describes what to consider when you create an Amazon EKS cluster. If you need to create a cluster on an AWS Outpost, see Local clusters for Amazon EKS on AWS Outposts. If this is your first time creating an Amazon EKS cluster, we recommend that you follow one of our Getting started with Amazon EKS guides. These guides help you to create a simple, default cluster without expanding into all of the available options.
Prerequisites
-
An existing VPC and subnets that meet Amazon EKS requirements. Before you deploy a cluster for production use, we recommend that you have a thorough understanding of the VPC and subnet requirements. If you don't have a VPC and subnets, you can create them using an Amazon EKS provided AWS CloudFormation template.
-
The
kubectl
command line tool is installed on your device or AWS CloudShell. The version can be the same as or up to one minor version earlier or later than the Kubernetes version of your cluster. For example, if your cluster version is1.27
, you can usekubectl
version1.26
,1.27
, or1.28
with it. To install or upgradekubectl
, see Installing or updating kubectl. -
Version
2.12.3
or later or1.27.160
or later of the AWS CLI installed and configured on your device or AWS CloudShell. You can check your current version withaws --version | cut -d / -f2 | cut -d ' ' -f1
. Package managers suchyum
,apt-get
, or Homebrew for macOS are often several versions behind the latest version of the AWS CLI. To install the latest version, see Installing, updating, and uninstalling the AWS CLI and Quick configuration withaws configure
in the AWS Command Line Interface User Guide. The AWS CLI version installed in the AWS CloudShell may also be several versions behind the latest version. To update it, see Installing AWS CLI to your home directory in the AWS CloudShell User Guide. -
An IAM principal with permissions to
create
anddescribe
an Amazon EKS cluster. For more information, see Create a local Kubernetes cluster on an Outpost and List or describe all clusters.
When an Amazon EKS cluster is created, the IAM principal that creates the cluster
is permanently added to the Kubernetes RBAC authorization table as the administrator. This principal
has system:masters
permissions. This principal isn't visible in
your cluster configuration. So, it's important to note the principal that created the cluster
and make sure that you never delete it. Initially, only the IAM principal that created the
server can make calls to the Kubernetes API server using kubectl
. If you use the console to
create the cluster, you must ensure that the same IAM credentials are in the AWS SDK
credential chain when you run kubectl
commands on your cluster. After your cluster is
created, you can grant other IAM principals access to your cluster.
To create an Amazon EKS cluster
If you already have a cluster IAM role, or you're going to create your cluster with
eksctl
, then you can skip this step. By default,eksctl
creates a role for you.To create an Amazon EKS cluster IAM role
-
Run the following command to create an IAM trust policy JSON file.
cat >
eks-cluster-role-trust-policy.json
<<EOF { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "eks.amazonaws.com" }, "Action": "sts:AssumeRole" } ] } EOF -
Create the Amazon EKS cluster IAM role. If necessary, preface
eks-cluster-role-trust-policy.json
with the path on your computer that you wrote the file to in the previous step. The command associates the trust policy that you created in the previous step to the role. To create an IAM role, the IAM principal that is creating the role must be assigned theiam:CreateRole
action (permission).aws iam create-role --role-name
myAmazonEKSClusterRole
--assume-role-policy-document file://"eks-cluster-role-trust-policy.json
" -
Attach the Amazon EKS managed policy named
AmazonEKSClusterPolicy
to the role. To attach an IAM policy to an IAM principal, the principal that is attaching the policy must be assigned one of the following IAM actions (permissions):iam:AttachUserPolicy
oriam:AttachRolePolicy
.aws iam attach-role-policy --policy-arn arn:aws:iam::aws:policy/AmazonEKSClusterPolicy --role-name
myAmazonEKSClusterRole
-
-
Create an Amazon EKS cluster.
You can create a cluster by using
eksctl
, the AWS Management Console, or the AWS CLI. -
If you created your cluster using
eksctl
, then you can skip this step. This is becauseeksctl
already completed this step for you. Enablekubectl
to communicate with your cluster by adding a new context to thekubectl
config
file. For more information about how to create and update the file, see Creating or updating a kubeconfig file for an Amazon EKS cluster.aws eks update-kubeconfig --region
region-code
--namemy-cluster
An example output is as follows.
Added new context arn:aws:eks:
region-code
:111122223333
:cluster/my-cluster
to/home/username/
.kube/config -
Confirm communication with your cluster by running the following command.
kubectl get svc
An example output is as follows.
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 28h
(Recommended) To use some Amazon EKS add-ons, or to enable individual Kubernetes workloads to have specific AWS Identity and Access Management (IAM) permissions, create an IAM OpenID Connect (OIDC) provider for your cluster. You only need to create an IAM OIDC provider for your cluster once. To learn more about Amazon EKS add-ons, see Amazon EKS add-ons. To learn more about assigning specific IAM permissions to your workloads, see IAM roles for service accounts.
(Recommended) Configure your cluster for the Amazon VPC CNI plugin for Kubernetes plugin before deploying Amazon EC2 nodes to your cluster. By default, the plugin was installed with your cluster. When you add Amazon EC2 nodes to your cluster, the plugin is automatically deployed to each Amazon EC2 node that you add. The plugin requires you to attach one of the following IAM policies to an IAM role:
AmazonEKS_CNI_Policy
managed IAM policyIf your cluster uses the
IPv4
family- An IAM policy that you create
If your cluster uses the
IPv6
family
The IAM role that you attach the policy to can be the node IAM role, or a dedicated role used only for the plugin. We recommend attaching the policy to this role. For more information about creating the role, see Configuring the Amazon VPC CNI plugin for Kubernetes to use IAM roles for service accounts or Amazon EKS node IAM role.
If you deployed your cluster using the AWS Management Console, you can skip this step. The AWS Management Console deploys the Amazon VPC CNI plugin for Kubernetes, CoreDNS, and
kube-proxy
Amazon EKS add-ons, by default.If you deploy your cluster using either
eksctl
or the AWS CLI, then the Amazon VPC CNI plugin for Kubernetes, CoreDNS, andkube-proxy
self-managed add-ons are deployed. You can migrate the Amazon VPC CNI plugin for Kubernetes, CoreDNS, andkube-proxy
self-managed add-ons that are deployed with your cluster to Amazon EKS add-ons. For more information, see Amazon EKS add-ons.-
If you plan to deploy workloads to your cluster that use Amazon EBS volumes , and you created a
1.23
or later cluster, then you must install the Amazon EBS CSI driver to your cluster before deploying the workloads.
Recommended next steps:
-
The IAM principal that created the cluster is the only principal that has access to the cluster. Grant permissions to other IAM principals so they can access your cluster.
-
If the IAM principal that created the cluster only has the minimum IAM permissions referenced in the prerequisites, then you might want to add additional Amazon EKS permissions for that principal. For more information about granting Amazon EKS permissions to IAM principals, see Identity and access management for Amazon EKS.
-
If you want the IAM principal that created the cluster, or any other principals to view Kubernetes resources in the Amazon EKS console, grant the Required permissions to the entities.
-
If you want nodes and IAM principals to access your cluster from within your VPC, enable the private endpoint for your cluster. The public endpoint is enabled by default. You can disable the public endpoint once you've enabled the private endpoint, if desired. For more information, see Amazon EKS cluster endpoint access control.